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"
73 #include <X11/Shell.h>
76 #include <X11/Xaw/Paned.h>
77 #include <X11/Xaw/Label.h>
78 #endif /* USE_MOTIF */
81 #undef USG /* ####KLUDGE for Solaris 2.2 and up */
90 #include "../lwlib/lwlib.h"
94 #include <Xm/DialogS.h>
95 #include <Xm/FileSB.h>
98 /* Do the EDITRES protocol if running X11R5
99 Exception: HP-UX (at least version A.09.05) has X11R5 without EditRes */
101 #if (XtSpecificationRelease >= 5) && !defined(NO_EDITRES)
103 extern void _XEditResCheckMessages ();
104 #endif /* R5 + Athena */
106 /* Unique id counter for widgets created by the Lucid Widget Library. */
108 extern LWLIB_ID widget_id_tick
;
111 /* This is part of a kludge--see lwlib/xlwmenu.c. */
112 extern XFontStruct
*xlwmenu_default_font
;
115 extern void free_frame_menubar ();
116 extern double atof ();
120 /* LessTif/Motif version info. */
122 static Lisp_Object Vmotif_version_string
;
124 #endif /* USE_MOTIF */
126 #endif /* USE_X_TOOLKIT */
129 #define MAXREQUEST(dpy) (XMaxRequestSize (dpy))
131 #define MAXREQUEST(dpy) ((dpy)->max_request_size)
134 /* The gray bitmap `bitmaps/gray'. This is done because xterm.c uses
135 it, and including `bitmaps/gray' more than once is a problem when
136 config.h defines `static' as an empty replacement string. */
138 int gray_bitmap_width
= gray_width
;
139 int gray_bitmap_height
= gray_height
;
140 char *gray_bitmap_bits
= gray_bits
;
142 /* Non-zero means we're allowed to display an hourglass cursor. */
144 int display_hourglass_p
;
146 /* The background and shape of the mouse pointer, and shape when not
147 over text or in the modeline. */
149 Lisp_Object Vx_pointer_shape
, Vx_nontext_pointer_shape
, Vx_mode_pointer_shape
;
150 Lisp_Object Vx_hourglass_pointer_shape
;
152 /* The shape when over mouse-sensitive text. */
154 Lisp_Object Vx_sensitive_text_pointer_shape
;
156 /* If non-nil, the pointer shape to indicate that windows can be
157 dragged horizontally. */
159 Lisp_Object Vx_window_horizontal_drag_shape
;
161 /* Color of chars displayed in cursor box. */
163 Lisp_Object Vx_cursor_fore_pixel
;
165 /* Nonzero if using X. */
169 /* Non nil if no window manager is in use. */
171 Lisp_Object Vx_no_window_manager
;
173 /* Search path for bitmap files. */
175 Lisp_Object Vx_bitmap_file_path
;
177 /* Regexp matching a font name whose width is the same as `PIXEL_SIZE'. */
179 Lisp_Object Vx_pixel_size_width_font_regexp
;
182 Lisp_Object Qsuppress_icon
;
183 Lisp_Object Qundefined_color
;
185 Lisp_Object Qcompound_text
, Qcancel_timer
;
189 extern Lisp_Object Vwindow_system_version
;
191 /* The below are defined in frame.c. */
194 int image_cache_refcount
, dpyinfo_refcount
;
199 /* Error if we are not connected to X. */
205 error ("X windows are not in use or not initialized");
208 /* Nonzero if we can use mouse menus.
209 You should not call this unless HAVE_MENUS is defined. */
217 /* Extract a frame as a FRAME_PTR, defaulting to the selected frame
218 and checking validity for X. */
221 check_x_frame (frame
)
227 frame
= selected_frame
;
228 CHECK_LIVE_FRAME (frame
);
231 error ("Non-X frame used");
235 /* Let the user specify an X display with a frame.
236 nil stands for the selected frame--or, if that is not an X frame,
237 the first X display on the list. */
239 struct x_display_info
*
240 check_x_display_info (frame
)
243 struct x_display_info
*dpyinfo
= NULL
;
247 struct frame
*sf
= XFRAME (selected_frame
);
249 if (FRAME_X_P (sf
) && FRAME_LIVE_P (sf
))
250 dpyinfo
= FRAME_X_DISPLAY_INFO (sf
);
251 else if (x_display_list
!= 0)
252 dpyinfo
= x_display_list
;
254 error ("X windows are not in use or not initialized");
256 else if (STRINGP (frame
))
257 dpyinfo
= x_display_info_for_name (frame
);
260 FRAME_PTR f
= check_x_frame (frame
);
261 dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
268 /* Return the Emacs frame-object corresponding to an X window.
269 It could be the frame's main window or an icon window. */
271 /* This function can be called during GC, so use GC_xxx type test macros. */
274 x_window_to_frame (dpyinfo
, wdesc
)
275 struct x_display_info
*dpyinfo
;
278 Lisp_Object tail
, frame
;
281 for (tail
= Vframe_list
; GC_CONSP (tail
); tail
= XCDR (tail
))
284 if (!GC_FRAMEP (frame
))
287 if (!FRAME_X_P (f
) || FRAME_X_DISPLAY_INFO (f
) != dpyinfo
)
289 if (f
->output_data
.x
->hourglass_window
== wdesc
)
292 if ((f
->output_data
.x
->edit_widget
293 && XtWindow (f
->output_data
.x
->edit_widget
) == wdesc
)
294 /* A tooltip frame? */
295 || (!f
->output_data
.x
->edit_widget
296 && FRAME_X_WINDOW (f
) == wdesc
)
297 || f
->output_data
.x
->icon_desc
== wdesc
)
299 #else /* not USE_X_TOOLKIT */
301 if (f
->output_data
.x
->edit_widget
)
303 GtkWidget
*gwdesc
= xg_win_to_widget (wdesc
);
304 struct x_output
*x
= f
->output_data
.x
;
305 if (gwdesc
!= 0 && gwdesc
== x
->edit_widget
)
309 if (FRAME_X_WINDOW (f
) == wdesc
310 || f
->output_data
.x
->icon_desc
== wdesc
)
312 #endif /* not USE_X_TOOLKIT */
317 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
318 /* Like x_window_to_frame but also compares the window with the widget's
322 x_any_window_to_frame (dpyinfo
, wdesc
)
323 struct x_display_info
*dpyinfo
;
326 Lisp_Object tail
, frame
;
327 struct frame
*f
, *found
;
331 for (tail
= Vframe_list
; GC_CONSP (tail
) && !found
; tail
= XCDR (tail
))
334 if (!GC_FRAMEP (frame
))
338 if (FRAME_X_P (f
) && FRAME_X_DISPLAY_INFO (f
) == dpyinfo
)
340 /* This frame matches if the window is any of its widgets. */
341 x
= f
->output_data
.x
;
342 if (x
->hourglass_window
== wdesc
)
347 GtkWidget
*gwdesc
= xg_win_to_widget (wdesc
);
349 && (gwdesc
== x
->widget
350 || gwdesc
== x
->edit_widget
351 || gwdesc
== x
->vbox_widget
352 || gwdesc
== x
->menubar_widget
))
355 if (wdesc
== XtWindow (x
->widget
)
356 || wdesc
== XtWindow (x
->column_widget
)
357 || wdesc
== XtWindow (x
->edit_widget
))
359 /* Match if the window is this frame's menubar. */
360 else if (lw_window_is_in_menubar (wdesc
, x
->menubar_widget
))
364 else if (FRAME_X_WINDOW (f
) == wdesc
)
365 /* A tooltip frame. */
373 /* Likewise, but exclude the menu bar widget. */
376 x_non_menubar_window_to_frame (dpyinfo
, wdesc
)
377 struct x_display_info
*dpyinfo
;
380 Lisp_Object tail
, frame
;
384 for (tail
= Vframe_list
; GC_CONSP (tail
); tail
= XCDR (tail
))
387 if (!GC_FRAMEP (frame
))
390 if (!FRAME_X_P (f
) || FRAME_X_DISPLAY_INFO (f
) != dpyinfo
)
392 x
= f
->output_data
.x
;
393 /* This frame matches if the window is any of its widgets. */
394 if (x
->hourglass_window
== wdesc
)
399 GtkWidget
*gwdesc
= xg_win_to_widget (wdesc
);
401 && (gwdesc
== x
->widget
402 || gwdesc
== x
->edit_widget
403 || gwdesc
== x
->vbox_widget
))
406 if (wdesc
== XtWindow (x
->widget
)
407 || wdesc
== XtWindow (x
->column_widget
)
408 || wdesc
== XtWindow (x
->edit_widget
))
412 else if (FRAME_X_WINDOW (f
) == wdesc
)
413 /* A tooltip frame. */
419 /* Likewise, but consider only the menu bar widget. */
422 x_menubar_window_to_frame (dpyinfo
, wdesc
)
423 struct x_display_info
*dpyinfo
;
426 Lisp_Object tail
, frame
;
430 for (tail
= Vframe_list
; GC_CONSP (tail
); tail
= XCDR (tail
))
433 if (!GC_FRAMEP (frame
))
436 if (!FRAME_X_P (f
) || FRAME_X_DISPLAY_INFO (f
) != dpyinfo
)
438 x
= f
->output_data
.x
;
439 /* Match if the window is this frame's menubar. */
441 if (x
->menubar_widget
)
443 GtkWidget
*gwdesc
= xg_win_to_widget (wdesc
);
448 && (gwdesc
== x
->menubar_widget
449 || gtk_widget_get_parent (gwdesc
) == x
->menubar_widget
))
455 if (x
->menubar_widget
456 && lw_window_is_in_menubar (wdesc
, x
->menubar_widget
))
463 /* Return the frame whose principal (outermost) window is WDESC.
464 If WDESC is some other (smaller) window, we return 0. */
467 x_top_window_to_frame (dpyinfo
, wdesc
)
468 struct x_display_info
*dpyinfo
;
471 Lisp_Object tail
, frame
;
475 for (tail
= Vframe_list
; GC_CONSP (tail
); tail
= XCDR (tail
))
478 if (!GC_FRAMEP (frame
))
481 if (!FRAME_X_P (f
) || FRAME_X_DISPLAY_INFO (f
) != dpyinfo
)
483 x
= f
->output_data
.x
;
487 /* This frame matches if the window is its topmost widget. */
489 GtkWidget
*gwdesc
= xg_win_to_widget (wdesc
);
490 if (gwdesc
== x
->widget
)
493 if (wdesc
== XtWindow (x
->widget
))
495 #if 0 /* I don't know why it did this,
496 but it seems logically wrong,
497 and it causes trouble for MapNotify events. */
498 /* Match if the window is this frame's menubar. */
499 if (x
->menubar_widget
500 && wdesc
== XtWindow (x
->menubar_widget
))
505 else if (FRAME_X_WINDOW (f
) == wdesc
)
511 #endif /* USE_X_TOOLKIT || USE_GTK */
515 /* Code to deal with bitmaps. Bitmaps are referenced by their bitmap
516 id, which is just an int that this section returns. Bitmaps are
517 reference counted so they can be shared among frames.
519 Bitmap indices are guaranteed to be > 0, so a negative number can
520 be used to indicate no bitmap.
522 If you use x_create_bitmap_from_data, then you must keep track of
523 the bitmaps yourself. That is, creating a bitmap from the same
524 data more than once will not be caught. */
527 /* Functions to access the contents of a bitmap, given an id. */
530 x_bitmap_height (f
, id
)
534 return FRAME_X_DISPLAY_INFO (f
)->bitmaps
[id
- 1].height
;
538 x_bitmap_width (f
, id
)
542 return FRAME_X_DISPLAY_INFO (f
)->bitmaps
[id
- 1].width
;
546 x_bitmap_pixmap (f
, id
)
550 return FRAME_X_DISPLAY_INFO (f
)->bitmaps
[id
- 1].pixmap
;
554 /* Allocate a new bitmap record. Returns index of new record. */
557 x_allocate_bitmap_record (f
)
560 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
563 if (dpyinfo
->bitmaps
== NULL
)
565 dpyinfo
->bitmaps_size
= 10;
567 = (struct x_bitmap_record
*) xmalloc (dpyinfo
->bitmaps_size
* sizeof (struct x_bitmap_record
));
568 dpyinfo
->bitmaps_last
= 1;
572 if (dpyinfo
->bitmaps_last
< dpyinfo
->bitmaps_size
)
573 return ++dpyinfo
->bitmaps_last
;
575 for (i
= 0; i
< dpyinfo
->bitmaps_size
; ++i
)
576 if (dpyinfo
->bitmaps
[i
].refcount
== 0)
579 dpyinfo
->bitmaps_size
*= 2;
581 = (struct x_bitmap_record
*) xrealloc (dpyinfo
->bitmaps
,
582 dpyinfo
->bitmaps_size
* sizeof (struct x_bitmap_record
));
583 return ++dpyinfo
->bitmaps_last
;
586 /* Add one reference to the reference count of the bitmap with id ID. */
589 x_reference_bitmap (f
, id
)
593 ++FRAME_X_DISPLAY_INFO (f
)->bitmaps
[id
- 1].refcount
;
596 /* Create a bitmap for frame F from a HEIGHT x WIDTH array of bits at BITS. */
599 x_create_bitmap_from_data (f
, bits
, width
, height
)
602 unsigned int width
, height
;
604 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
608 bitmap
= XCreateBitmapFromData (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
609 bits
, width
, height
);
616 id
= x_allocate_bitmap_record (f
);
617 dpyinfo
->bitmaps
[id
- 1].pixmap
= bitmap
;
618 dpyinfo
->bitmaps
[id
- 1].file
= NULL
;
619 dpyinfo
->bitmaps
[id
- 1].refcount
= 1;
620 dpyinfo
->bitmaps
[id
- 1].depth
= 1;
621 dpyinfo
->bitmaps
[id
- 1].height
= height
;
622 dpyinfo
->bitmaps
[id
- 1].width
= width
;
627 /* Create bitmap from file FILE for frame F. */
630 x_create_bitmap_from_file (f
, file
)
634 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
635 unsigned int width
, height
;
637 int xhot
, yhot
, result
, id
;
642 /* Look for an existing bitmap with the same name. */
643 for (id
= 0; id
< dpyinfo
->bitmaps_last
; ++id
)
645 if (dpyinfo
->bitmaps
[id
].refcount
646 && dpyinfo
->bitmaps
[id
].file
647 && !strcmp (dpyinfo
->bitmaps
[id
].file
, (char *) SDATA (file
)))
649 ++dpyinfo
->bitmaps
[id
].refcount
;
654 /* Search bitmap-file-path for the file, if appropriate. */
655 fd
= openp (Vx_bitmap_file_path
, file
, Qnil
, &found
, Qnil
);
660 filename
= (char *) SDATA (found
);
662 result
= XReadBitmapFile (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
663 filename
, &width
, &height
, &bitmap
, &xhot
, &yhot
);
664 if (result
!= BitmapSuccess
)
667 id
= x_allocate_bitmap_record (f
);
668 dpyinfo
->bitmaps
[id
- 1].pixmap
= bitmap
;
669 dpyinfo
->bitmaps
[id
- 1].refcount
= 1;
670 dpyinfo
->bitmaps
[id
- 1].file
671 = (char *) xmalloc (SBYTES (file
) + 1);
672 dpyinfo
->bitmaps
[id
- 1].depth
= 1;
673 dpyinfo
->bitmaps
[id
- 1].height
= height
;
674 dpyinfo
->bitmaps
[id
- 1].width
= width
;
675 strcpy (dpyinfo
->bitmaps
[id
- 1].file
, SDATA (file
));
680 /* Remove reference to bitmap with id number ID. */
683 x_destroy_bitmap (f
, id
)
687 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
691 --dpyinfo
->bitmaps
[id
- 1].refcount
;
692 if (dpyinfo
->bitmaps
[id
- 1].refcount
== 0)
695 XFreePixmap (FRAME_X_DISPLAY (f
), dpyinfo
->bitmaps
[id
- 1].pixmap
);
696 if (dpyinfo
->bitmaps
[id
- 1].file
)
698 xfree (dpyinfo
->bitmaps
[id
- 1].file
);
699 dpyinfo
->bitmaps
[id
- 1].file
= NULL
;
706 /* Free all the bitmaps for the display specified by DPYINFO. */
709 x_destroy_all_bitmaps (dpyinfo
)
710 struct x_display_info
*dpyinfo
;
713 for (i
= 0; i
< dpyinfo
->bitmaps_last
; i
++)
714 if (dpyinfo
->bitmaps
[i
].refcount
> 0)
716 XFreePixmap (dpyinfo
->display
, dpyinfo
->bitmaps
[i
].pixmap
);
717 if (dpyinfo
->bitmaps
[i
].file
)
718 xfree (dpyinfo
->bitmaps
[i
].file
);
720 dpyinfo
->bitmaps_last
= 0;
724 static Lisp_Object unwind_create_frame
P_ ((Lisp_Object
));
725 static Lisp_Object unwind_create_tip_frame
P_ ((Lisp_Object
));
726 static void x_disable_image
P_ ((struct frame
*, struct image
*));
728 void x_set_foreground_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
729 static void x_set_wait_for_wm
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
730 void x_set_background_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
731 void x_set_mouse_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
732 void x_set_cursor_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
733 void x_set_border_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
734 void x_set_cursor_type
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
735 void x_set_icon_type
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
736 void x_set_icon_name
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
737 void x_explicitly_set_name
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
738 void x_set_menu_bar_lines
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
739 void x_set_title
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
740 void x_set_tool_bar_lines
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
741 void x_set_scroll_bar_foreground
P_ ((struct frame
*, Lisp_Object
,
743 void x_set_scroll_bar_background
P_ ((struct frame
*, Lisp_Object
,
745 static Lisp_Object x_default_scroll_bar_color_parameter
P_ ((struct frame
*,
750 static void x_edge_detection
P_ ((struct frame
*, struct image
*, Lisp_Object
,
752 static void init_color_table
P_ ((void));
753 static void free_color_table
P_ ((void));
754 static unsigned long *colors_in_color_table
P_ ((int *n
));
755 static unsigned long lookup_rgb_color
P_ ((struct frame
*f
, int r
, int g
, int b
));
756 static unsigned long lookup_pixel_color
P_ ((struct frame
*f
, unsigned long p
));
762 /* Store the screen positions of frame F into XPTR and YPTR.
763 These are the positions of the containing window manager window,
764 not Emacs's own window. */
767 x_real_positions (f
, xptr
, yptr
)
771 int win_x
, win_y
, outer_x
, outer_y
;
772 int real_x
= 0, real_y
= 0;
774 Window win
= f
->output_data
.x
->parent_desc
;
780 count
= x_catch_errors (FRAME_X_DISPLAY (f
));
782 if (win
== FRAME_X_DISPLAY_INFO (f
)->root_window
)
783 win
= FRAME_OUTER_WINDOW (f
);
785 /* This loop traverses up the containment tree until we hit the root
786 window. Window managers may intersect many windows between our window
787 and the root window. The window we find just before the root window
788 should be the outer WM window. */
791 Window wm_window
, rootw
;
792 Window
*tmp_children
;
793 unsigned int tmp_nchildren
;
796 success
= XQueryTree (FRAME_X_DISPLAY (f
), win
, &rootw
,
797 &wm_window
, &tmp_children
, &tmp_nchildren
);
799 had_errors
= x_had_errors_p (FRAME_X_DISPLAY (f
));
801 /* Don't free tmp_children if XQueryTree failed. */
805 XFree ((char *) tmp_children
);
807 if (wm_window
== rootw
|| had_errors
)
818 /* Get the real coordinates for the WM window upper left corner */
819 XGetGeometry (FRAME_X_DISPLAY (f
), win
,
820 &rootw
, &real_x
, &real_y
, &ign
, &ign
, &ign
, &ign
);
822 /* Translate real coordinates to coordinates relative to our
823 window. For our window, the upper left corner is 0, 0.
824 Since the upper left corner of the WM window is outside
825 our window, win_x and win_y will be negative:
827 ------------------ ---> x
829 | ----------------- v y
832 XTranslateCoordinates (FRAME_X_DISPLAY (f
),
834 /* From-window, to-window. */
835 FRAME_X_DISPLAY_INFO (f
)->root_window
,
838 /* From-position, to-position. */
839 real_x
, real_y
, &win_x
, &win_y
,
844 if (FRAME_X_WINDOW (f
) == FRAME_OUTER_WINDOW (f
))
851 XTranslateCoordinates (FRAME_X_DISPLAY (f
),
853 /* From-window, to-window. */
854 FRAME_X_DISPLAY_INFO (f
)->root_window
,
855 FRAME_OUTER_WINDOW (f
),
857 /* From-position, to-position. */
858 real_x
, real_y
, &outer_x
, &outer_y
,
864 had_errors
= x_had_errors_p (FRAME_X_DISPLAY (f
));
867 x_uncatch_errors (FRAME_X_DISPLAY (f
), count
);
871 if (had_errors
) return;
873 f
->output_data
.x
->x_pixels_diff
= -win_x
;
874 f
->output_data
.x
->y_pixels_diff
= -win_y
;
875 f
->output_data
.x
->x_pixels_outer_diff
= -outer_x
;
876 f
->output_data
.x
->y_pixels_outer_diff
= -outer_y
;
885 /* Gamma-correct COLOR on frame F. */
888 gamma_correct (f
, color
)
894 color
->red
= pow (color
->red
/ 65535.0, f
->gamma
) * 65535.0 + 0.5;
895 color
->green
= pow (color
->green
/ 65535.0, f
->gamma
) * 65535.0 + 0.5;
896 color
->blue
= pow (color
->blue
/ 65535.0, f
->gamma
) * 65535.0 + 0.5;
901 /* Decide if color named COLOR_NAME is valid for use on frame F. If
902 so, return the RGB values in COLOR. If ALLOC_P is non-zero,
903 allocate the color. Value is zero if COLOR_NAME is invalid, or
904 no color could be allocated. */
907 x_defined_color (f
, color_name
, color
, alloc_p
)
914 Display
*dpy
= FRAME_X_DISPLAY (f
);
915 Colormap cmap
= FRAME_X_COLORMAP (f
);
918 success_p
= XParseColor (dpy
, cmap
, color_name
, color
);
919 if (success_p
&& alloc_p
)
920 success_p
= x_alloc_nearest_color (f
, cmap
, color
);
927 /* Return the pixel color value for color COLOR_NAME on frame F. If F
928 is a monochrome frame, return MONO_COLOR regardless of what ARG says.
929 Signal an error if color can't be allocated. */
932 x_decode_color (f
, color_name
, mono_color
)
934 Lisp_Object color_name
;
939 CHECK_STRING (color_name
);
941 #if 0 /* Don't do this. It's wrong when we're not using the default
942 colormap, it makes freeing difficult, and it's probably not
943 an important optimization. */
944 if (strcmp (SDATA (color_name
), "black") == 0)
945 return BLACK_PIX_DEFAULT (f
);
946 else if (strcmp (SDATA (color_name
), "white") == 0)
947 return WHITE_PIX_DEFAULT (f
);
950 /* Return MONO_COLOR for monochrome frames. */
951 if (FRAME_X_DISPLAY_INFO (f
)->n_planes
== 1)
954 /* x_defined_color is responsible for coping with failures
955 by looking for a near-miss. */
956 if (x_defined_color (f
, SDATA (color_name
), &cdef
, 1))
959 Fsignal (Qerror
, Fcons (build_string ("Undefined color"),
960 Fcons (color_name
, Qnil
)));
966 /* Change the `wait-for-wm' frame parameter of frame F. OLD_VALUE is
967 the previous value of that parameter, NEW_VALUE is the new value.
968 See also the comment of wait_for_wm in struct x_output. */
971 x_set_wait_for_wm (f
, new_value
, old_value
)
973 Lisp_Object new_value
, old_value
;
975 f
->output_data
.x
->wait_for_wm
= !NILP (new_value
);
979 /* Functions called only from `x_set_frame_param'
980 to set individual parameters.
982 If FRAME_X_WINDOW (f) is 0,
983 the frame is being created and its X-window does not exist yet.
984 In that case, just record the parameter's new value
985 in the standard place; do not attempt to change the window. */
988 x_set_foreground_color (f
, arg
, oldval
)
990 Lisp_Object arg
, oldval
;
992 struct x_output
*x
= f
->output_data
.x
;
993 unsigned long fg
, old_fg
;
995 fg
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
996 old_fg
= x
->foreground_pixel
;
997 x
->foreground_pixel
= fg
;
999 if (FRAME_X_WINDOW (f
) != 0)
1001 Display
*dpy
= FRAME_X_DISPLAY (f
);
1004 XSetForeground (dpy
, x
->normal_gc
, fg
);
1005 XSetBackground (dpy
, x
->reverse_gc
, fg
);
1007 if (x
->cursor_pixel
== old_fg
)
1009 unload_color (f
, x
->cursor_pixel
);
1010 x
->cursor_pixel
= x_copy_color (f
, fg
);
1011 XSetBackground (dpy
, x
->cursor_gc
, x
->cursor_pixel
);
1016 update_face_from_frame_parameter (f
, Qforeground_color
, arg
);
1018 if (FRAME_VISIBLE_P (f
))
1022 unload_color (f
, old_fg
);
1026 x_set_background_color (f
, arg
, oldval
)
1028 Lisp_Object arg
, oldval
;
1030 struct x_output
*x
= f
->output_data
.x
;
1033 bg
= x_decode_color (f
, arg
, WHITE_PIX_DEFAULT (f
));
1034 unload_color (f
, x
->background_pixel
);
1035 x
->background_pixel
= bg
;
1037 if (FRAME_X_WINDOW (f
) != 0)
1039 Display
*dpy
= FRAME_X_DISPLAY (f
);
1042 XSetBackground (dpy
, x
->normal_gc
, bg
);
1043 XSetForeground (dpy
, x
->reverse_gc
, bg
);
1044 XSetWindowBackground (dpy
, FRAME_X_WINDOW (f
), bg
);
1045 XSetForeground (dpy
, x
->cursor_gc
, bg
);
1048 xg_set_background_color (f
, bg
);
1051 #ifndef USE_TOOLKIT_SCROLL_BARS /* Turns out to be annoying with
1052 toolkit scroll bars. */
1055 for (bar
= FRAME_SCROLL_BARS (f
);
1057 bar
= XSCROLL_BAR (bar
)->next
)
1059 Window window
= SCROLL_BAR_X_WINDOW (XSCROLL_BAR (bar
));
1060 XSetWindowBackground (dpy
, window
, bg
);
1063 #endif /* USE_TOOLKIT_SCROLL_BARS */
1066 update_face_from_frame_parameter (f
, Qbackground_color
, arg
);
1068 if (FRAME_VISIBLE_P (f
))
1074 x_set_mouse_color (f
, arg
, oldval
)
1076 Lisp_Object arg
, oldval
;
1078 struct x_output
*x
= f
->output_data
.x
;
1079 Display
*dpy
= FRAME_X_DISPLAY (f
);
1080 Cursor cursor
, nontext_cursor
, mode_cursor
, hand_cursor
;
1081 Cursor hourglass_cursor
, horizontal_drag_cursor
;
1083 unsigned long pixel
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
1084 unsigned long mask_color
= x
->background_pixel
;
1086 /* Don't let pointers be invisible. */
1087 if (mask_color
== pixel
)
1089 x_free_colors (f
, &pixel
, 1);
1090 pixel
= x_copy_color (f
, x
->foreground_pixel
);
1093 unload_color (f
, x
->mouse_pixel
);
1094 x
->mouse_pixel
= pixel
;
1098 /* It's not okay to crash if the user selects a screwy cursor. */
1099 count
= x_catch_errors (dpy
);
1101 if (!NILP (Vx_pointer_shape
))
1103 CHECK_NUMBER (Vx_pointer_shape
);
1104 cursor
= XCreateFontCursor (dpy
, XINT (Vx_pointer_shape
));
1107 cursor
= XCreateFontCursor (dpy
, XC_xterm
);
1108 x_check_errors (dpy
, "bad text pointer cursor: %s");
1110 if (!NILP (Vx_nontext_pointer_shape
))
1112 CHECK_NUMBER (Vx_nontext_pointer_shape
);
1114 = XCreateFontCursor (dpy
, XINT (Vx_nontext_pointer_shape
));
1117 nontext_cursor
= XCreateFontCursor (dpy
, XC_left_ptr
);
1118 x_check_errors (dpy
, "bad nontext pointer cursor: %s");
1120 if (!NILP (Vx_hourglass_pointer_shape
))
1122 CHECK_NUMBER (Vx_hourglass_pointer_shape
);
1124 = XCreateFontCursor (dpy
, XINT (Vx_hourglass_pointer_shape
));
1127 hourglass_cursor
= XCreateFontCursor (dpy
, XC_watch
);
1128 x_check_errors (dpy
, "bad hourglass pointer cursor: %s");
1130 x_check_errors (dpy
, "bad nontext pointer cursor: %s");
1131 if (!NILP (Vx_mode_pointer_shape
))
1133 CHECK_NUMBER (Vx_mode_pointer_shape
);
1134 mode_cursor
= XCreateFontCursor (dpy
, XINT (Vx_mode_pointer_shape
));
1137 mode_cursor
= XCreateFontCursor (dpy
, XC_xterm
);
1138 x_check_errors (dpy
, "bad modeline pointer cursor: %s");
1140 if (!NILP (Vx_sensitive_text_pointer_shape
))
1142 CHECK_NUMBER (Vx_sensitive_text_pointer_shape
);
1144 = XCreateFontCursor (dpy
, XINT (Vx_sensitive_text_pointer_shape
));
1147 hand_cursor
= XCreateFontCursor (dpy
, XC_hand2
);
1149 if (!NILP (Vx_window_horizontal_drag_shape
))
1151 CHECK_NUMBER (Vx_window_horizontal_drag_shape
);
1152 horizontal_drag_cursor
1153 = XCreateFontCursor (dpy
, XINT (Vx_window_horizontal_drag_shape
));
1156 horizontal_drag_cursor
1157 = XCreateFontCursor (dpy
, XC_sb_h_double_arrow
);
1159 /* Check and report errors with the above calls. */
1160 x_check_errors (dpy
, "can't set cursor shape: %s");
1161 x_uncatch_errors (dpy
, count
);
1164 XColor fore_color
, back_color
;
1166 fore_color
.pixel
= x
->mouse_pixel
;
1167 x_query_color (f
, &fore_color
);
1168 back_color
.pixel
= mask_color
;
1169 x_query_color (f
, &back_color
);
1171 XRecolorCursor (dpy
, cursor
, &fore_color
, &back_color
);
1172 XRecolorCursor (dpy
, nontext_cursor
, &fore_color
, &back_color
);
1173 XRecolorCursor (dpy
, mode_cursor
, &fore_color
, &back_color
);
1174 XRecolorCursor (dpy
, hand_cursor
, &fore_color
, &back_color
);
1175 XRecolorCursor (dpy
, hourglass_cursor
, &fore_color
, &back_color
);
1176 XRecolorCursor (dpy
, horizontal_drag_cursor
, &fore_color
, &back_color
);
1179 if (FRAME_X_WINDOW (f
) != 0)
1180 XDefineCursor (dpy
, FRAME_X_WINDOW (f
), cursor
);
1182 if (cursor
!= x
->text_cursor
1183 && x
->text_cursor
!= 0)
1184 XFreeCursor (dpy
, x
->text_cursor
);
1185 x
->text_cursor
= cursor
;
1187 if (nontext_cursor
!= x
->nontext_cursor
1188 && x
->nontext_cursor
!= 0)
1189 XFreeCursor (dpy
, x
->nontext_cursor
);
1190 x
->nontext_cursor
= nontext_cursor
;
1192 if (hourglass_cursor
!= x
->hourglass_cursor
1193 && x
->hourglass_cursor
!= 0)
1194 XFreeCursor (dpy
, x
->hourglass_cursor
);
1195 x
->hourglass_cursor
= hourglass_cursor
;
1197 if (mode_cursor
!= x
->modeline_cursor
1198 && x
->modeline_cursor
!= 0)
1199 XFreeCursor (dpy
, f
->output_data
.x
->modeline_cursor
);
1200 x
->modeline_cursor
= mode_cursor
;
1202 if (hand_cursor
!= x
->hand_cursor
1203 && x
->hand_cursor
!= 0)
1204 XFreeCursor (dpy
, x
->hand_cursor
);
1205 x
->hand_cursor
= hand_cursor
;
1207 if (horizontal_drag_cursor
!= x
->horizontal_drag_cursor
1208 && x
->horizontal_drag_cursor
!= 0)
1209 XFreeCursor (dpy
, x
->horizontal_drag_cursor
);
1210 x
->horizontal_drag_cursor
= horizontal_drag_cursor
;
1215 update_face_from_frame_parameter (f
, Qmouse_color
, arg
);
1219 x_set_cursor_color (f
, arg
, oldval
)
1221 Lisp_Object arg
, oldval
;
1223 unsigned long fore_pixel
, pixel
;
1224 int fore_pixel_allocated_p
= 0, pixel_allocated_p
= 0;
1225 struct x_output
*x
= f
->output_data
.x
;
1227 if (!NILP (Vx_cursor_fore_pixel
))
1229 fore_pixel
= x_decode_color (f
, Vx_cursor_fore_pixel
,
1230 WHITE_PIX_DEFAULT (f
));
1231 fore_pixel_allocated_p
= 1;
1234 fore_pixel
= x
->background_pixel
;
1236 pixel
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
1237 pixel_allocated_p
= 1;
1239 /* Make sure that the cursor color differs from the background color. */
1240 if (pixel
== x
->background_pixel
)
1242 if (pixel_allocated_p
)
1244 x_free_colors (f
, &pixel
, 1);
1245 pixel_allocated_p
= 0;
1248 pixel
= x
->mouse_pixel
;
1249 if (pixel
== fore_pixel
)
1251 if (fore_pixel_allocated_p
)
1253 x_free_colors (f
, &fore_pixel
, 1);
1254 fore_pixel_allocated_p
= 0;
1256 fore_pixel
= x
->background_pixel
;
1260 unload_color (f
, x
->cursor_foreground_pixel
);
1261 if (!fore_pixel_allocated_p
)
1262 fore_pixel
= x_copy_color (f
, fore_pixel
);
1263 x
->cursor_foreground_pixel
= fore_pixel
;
1265 unload_color (f
, x
->cursor_pixel
);
1266 if (!pixel_allocated_p
)
1267 pixel
= x_copy_color (f
, pixel
);
1268 x
->cursor_pixel
= pixel
;
1270 if (FRAME_X_WINDOW (f
) != 0)
1273 XSetBackground (FRAME_X_DISPLAY (f
), x
->cursor_gc
, x
->cursor_pixel
);
1274 XSetForeground (FRAME_X_DISPLAY (f
), x
->cursor_gc
, fore_pixel
);
1277 if (FRAME_VISIBLE_P (f
))
1279 x_update_cursor (f
, 0);
1280 x_update_cursor (f
, 1);
1284 update_face_from_frame_parameter (f
, Qcursor_color
, arg
);
1287 /* Set the border-color of frame F to pixel value PIX.
1288 Note that this does not fully take effect if done before
1289 F has an x-window. */
1292 x_set_border_pixel (f
, pix
)
1296 unload_color (f
, f
->output_data
.x
->border_pixel
);
1297 f
->output_data
.x
->border_pixel
= pix
;
1299 if (FRAME_X_WINDOW (f
) != 0 && f
->output_data
.x
->border_width
> 0)
1302 XSetWindowBorder (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
1303 (unsigned long)pix
);
1306 if (FRAME_VISIBLE_P (f
))
1311 /* Set the border-color of frame F to value described by ARG.
1312 ARG can be a string naming a color.
1313 The border-color is used for the border that is drawn by the X server.
1314 Note that this does not fully take effect if done before
1315 F has an x-window; it must be redone when the window is created.
1317 Note: this is done in two routines because of the way X10 works.
1319 Note: under X11, this is normally the province of the window manager,
1320 and so emacs' border colors may be overridden. */
1323 x_set_border_color (f
, arg
, oldval
)
1325 Lisp_Object arg
, oldval
;
1330 pix
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
1331 x_set_border_pixel (f
, pix
);
1332 update_face_from_frame_parameter (f
, Qborder_color
, arg
);
1337 x_set_cursor_type (f
, arg
, oldval
)
1339 Lisp_Object arg
, oldval
;
1341 set_frame_cursor_types (f
, arg
);
1343 /* Make sure the cursor gets redrawn. */
1344 cursor_type_changed
= 1;
1348 x_set_icon_type (f
, arg
, oldval
)
1350 Lisp_Object arg
, oldval
;
1356 if (STRINGP (oldval
) && EQ (Fstring_equal (oldval
, arg
), Qt
))
1359 else if (!STRINGP (oldval
) && EQ (oldval
, Qnil
) == EQ (arg
, Qnil
))
1364 result
= x_text_icon (f
,
1365 (char *) SDATA ((!NILP (f
->icon_name
)
1369 result
= x_bitmap_icon (f
, arg
);
1374 error ("No icon window available");
1377 XFlush (FRAME_X_DISPLAY (f
));
1382 x_set_icon_name (f
, arg
, oldval
)
1384 Lisp_Object arg
, oldval
;
1390 if (STRINGP (oldval
) && EQ (Fstring_equal (oldval
, arg
), Qt
))
1393 else if (!STRINGP (oldval
) && EQ (oldval
, Qnil
) == EQ (arg
, Qnil
))
1398 if (f
->output_data
.x
->icon_bitmap
!= 0)
1403 result
= x_text_icon (f
,
1404 (char *) SDATA ((!NILP (f
->icon_name
)
1413 error ("No icon window available");
1416 XFlush (FRAME_X_DISPLAY (f
));
1422 x_set_menu_bar_lines (f
, value
, oldval
)
1424 Lisp_Object value
, oldval
;
1427 #ifndef USE_X_TOOLKIT
1428 int olines
= FRAME_MENU_BAR_LINES (f
);
1431 /* Right now, menu bars don't work properly in minibuf-only frames;
1432 most of the commands try to apply themselves to the minibuffer
1433 frame itself, and get an error because you can't switch buffers
1434 in or split the minibuffer window. */
1435 if (FRAME_MINIBUF_ONLY_P (f
))
1438 if (INTEGERP (value
))
1439 nlines
= XINT (value
);
1443 /* Make sure we redisplay all windows in this frame. */
1444 windows_or_buffers_changed
++;
1446 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
1447 FRAME_MENU_BAR_LINES (f
) = 0;
1450 FRAME_EXTERNAL_MENU_BAR (f
) = 1;
1451 if (FRAME_X_P (f
) && f
->output_data
.x
->menubar_widget
== 0)
1452 /* Make sure next redisplay shows the menu bar. */
1453 XWINDOW (FRAME_SELECTED_WINDOW (f
))->update_mode_line
= Qt
;
1457 if (FRAME_EXTERNAL_MENU_BAR (f
) == 1)
1458 free_frame_menubar (f
);
1459 FRAME_EXTERNAL_MENU_BAR (f
) = 0;
1461 f
->output_data
.x
->menubar_widget
= 0;
1463 #else /* not USE_X_TOOLKIT && not USE_GTK */
1464 FRAME_MENU_BAR_LINES (f
) = nlines
;
1465 change_window_heights (f
->root_window
, nlines
- olines
);
1466 #endif /* not USE_X_TOOLKIT */
1471 /* Set the number of lines used for the tool bar of frame F to VALUE.
1472 VALUE not an integer, or < 0 means set the lines to zero. OLDVAL
1473 is the old number of tool bar lines. This function changes the
1474 height of all windows on frame F to match the new tool bar height.
1475 The frame's height doesn't change. */
1478 x_set_tool_bar_lines (f
, value
, oldval
)
1480 Lisp_Object value
, oldval
;
1482 int delta
, nlines
, root_height
;
1483 Lisp_Object root_window
;
1485 /* Treat tool bars like menu bars. */
1486 if (FRAME_MINIBUF_ONLY_P (f
))
1489 /* Use VALUE only if an integer >= 0. */
1490 if (INTEGERP (value
) && XINT (value
) >= 0)
1491 nlines
= XFASTINT (value
);
1496 FRAME_TOOL_BAR_LINES (f
) = 0;
1499 FRAME_EXTERNAL_TOOL_BAR (f
) = 1;
1500 if (FRAME_X_P (f
) && f
->output_data
.x
->toolbar_widget
== 0)
1501 /* Make sure next redisplay shows the tool bar. */
1502 XWINDOW (FRAME_SELECTED_WINDOW (f
))->update_mode_line
= Qt
;
1503 update_frame_tool_bar (f
);
1507 if (FRAME_EXTERNAL_TOOL_BAR (f
))
1508 free_frame_tool_bar (f
);
1509 FRAME_EXTERNAL_TOOL_BAR (f
) = 0;
1515 /* Make sure we redisplay all windows in this frame. */
1516 ++windows_or_buffers_changed
;
1518 delta
= nlines
- FRAME_TOOL_BAR_LINES (f
);
1520 /* Don't resize the tool-bar to more than we have room for. */
1521 root_window
= FRAME_ROOT_WINDOW (f
);
1522 root_height
= XINT (XWINDOW (root_window
)->height
);
1523 if (root_height
- delta
< 1)
1525 delta
= root_height
- 1;
1526 nlines
= FRAME_TOOL_BAR_LINES (f
) + delta
;
1529 FRAME_TOOL_BAR_LINES (f
) = nlines
;
1530 change_window_heights (root_window
, delta
);
1533 /* We also have to make sure that the internal border at the top of
1534 the frame, below the menu bar or tool bar, is redrawn when the
1535 tool bar disappears. This is so because the internal border is
1536 below the tool bar if one is displayed, but is below the menu bar
1537 if there isn't a tool bar. The tool bar draws into the area
1538 below the menu bar. */
1539 if (FRAME_X_WINDOW (f
) && FRAME_TOOL_BAR_LINES (f
) == 0)
1543 clear_current_matrices (f
);
1544 updating_frame
= NULL
;
1547 /* If the tool bar gets smaller, the internal border below it
1548 has to be cleared. It was formerly part of the display
1549 of the larger tool bar, and updating windows won't clear it. */
1552 int height
= FRAME_INTERNAL_BORDER_WIDTH (f
);
1553 int width
= PIXEL_WIDTH (f
);
1554 int y
= nlines
* CANON_Y_UNIT (f
);
1557 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
1558 0, y
, width
, height
, False
);
1561 if (WINDOWP (f
->tool_bar_window
))
1562 clear_glyph_matrix (XWINDOW (f
->tool_bar_window
)->current_matrix
);
1567 /* Set the foreground color for scroll bars on frame F to VALUE.
1568 VALUE should be a string, a color name. If it isn't a string or
1569 isn't a valid color name, do nothing. OLDVAL is the old value of
1570 the frame parameter. */
1573 x_set_scroll_bar_foreground (f
, value
, oldval
)
1575 Lisp_Object value
, oldval
;
1577 unsigned long pixel
;
1579 if (STRINGP (value
))
1580 pixel
= x_decode_color (f
, value
, BLACK_PIX_DEFAULT (f
));
1584 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
1585 unload_color (f
, f
->output_data
.x
->scroll_bar_foreground_pixel
);
1587 f
->output_data
.x
->scroll_bar_foreground_pixel
= pixel
;
1588 if (FRAME_X_WINDOW (f
) && FRAME_VISIBLE_P (f
))
1590 /* Remove all scroll bars because they have wrong colors. */
1591 if (condemn_scroll_bars_hook
)
1592 (*condemn_scroll_bars_hook
) (f
);
1593 if (judge_scroll_bars_hook
)
1594 (*judge_scroll_bars_hook
) (f
);
1596 update_face_from_frame_parameter (f
, Qscroll_bar_foreground
, value
);
1602 /* Set the background color for scroll bars on frame F to VALUE VALUE
1603 should be a string, a color name. If it isn't a string or isn't a
1604 valid color name, do nothing. OLDVAL is the old value of the frame
1608 x_set_scroll_bar_background (f
, value
, oldval
)
1610 Lisp_Object value
, oldval
;
1612 unsigned long pixel
;
1614 if (STRINGP (value
))
1615 pixel
= x_decode_color (f
, value
, WHITE_PIX_DEFAULT (f
));
1619 if (f
->output_data
.x
->scroll_bar_background_pixel
!= -1)
1620 unload_color (f
, f
->output_data
.x
->scroll_bar_background_pixel
);
1622 #ifdef USE_TOOLKIT_SCROLL_BARS
1623 /* Scrollbar shadow colors. */
1624 if (f
->output_data
.x
->scroll_bar_top_shadow_pixel
!= -1)
1626 unload_color (f
, f
->output_data
.x
->scroll_bar_top_shadow_pixel
);
1627 f
->output_data
.x
->scroll_bar_top_shadow_pixel
= -1;
1629 if (f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
!= -1)
1631 unload_color (f
, f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
);
1632 f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
= -1;
1634 #endif /* USE_TOOLKIT_SCROLL_BARS */
1636 f
->output_data
.x
->scroll_bar_background_pixel
= pixel
;
1637 if (FRAME_X_WINDOW (f
) && FRAME_VISIBLE_P (f
))
1639 /* Remove all scroll bars because they have wrong colors. */
1640 if (condemn_scroll_bars_hook
)
1641 (*condemn_scroll_bars_hook
) (f
);
1642 if (judge_scroll_bars_hook
)
1643 (*judge_scroll_bars_hook
) (f
);
1645 update_face_from_frame_parameter (f
, Qscroll_bar_background
, value
);
1651 /* Encode Lisp string STRING as a text in a format appropriate for
1652 XICCC (X Inter Client Communication Conventions).
1654 If STRING contains only ASCII characters, do no conversion and
1655 return the string data of STRING. Otherwise, encode the text by
1656 CODING_SYSTEM, and return a newly allocated memory area which
1657 should be freed by `xfree' by a caller.
1659 SELECTIONP non-zero means the string is being encoded for an X
1660 selection, so it is safe to run pre-write conversions (which
1663 Store the byte length of resulting text in *TEXT_BYTES.
1665 If the text contains only ASCII and Latin-1, store 1 in *STRING_P,
1666 which means that the `encoding' of the result can be `STRING'.
1667 Otherwise store 0 in *STRINGP, which means that the `encoding' of
1668 the result should be `COMPOUND_TEXT'. */
1671 x_encode_text (string
, coding_system
, selectionp
, text_bytes
, stringp
)
1672 Lisp_Object string
, coding_system
;
1673 int *text_bytes
, *stringp
;
1676 unsigned char *str
= SDATA (string
);
1677 int chars
= SCHARS (string
);
1678 int bytes
= SBYTES (string
);
1682 struct coding_system coding
;
1683 extern Lisp_Object Qcompound_text_with_extensions
;
1685 charset_info
= find_charset_in_text (str
, chars
, bytes
, NULL
, Qnil
);
1686 if (charset_info
== 0)
1688 /* No multibyte character in OBJ. We need not encode it. */
1689 *text_bytes
= bytes
;
1694 setup_coding_system (coding_system
, &coding
);
1696 && SYMBOLP (coding
.pre_write_conversion
)
1697 && !NILP (Ffboundp (coding
.pre_write_conversion
)))
1699 string
= run_pre_post_conversion_on_str (string
, &coding
, 1);
1700 str
= SDATA (string
);
1701 chars
= SCHARS (string
);
1702 bytes
= SBYTES (string
);
1704 coding
.src_multibyte
= 1;
1705 coding
.dst_multibyte
= 0;
1706 coding
.mode
|= CODING_MODE_LAST_BLOCK
;
1707 if (coding
.type
== coding_type_iso2022
)
1708 coding
.flags
|= CODING_FLAG_ISO_SAFE
;
1709 /* We suppress producing escape sequences for composition. */
1710 coding
.composing
= COMPOSITION_DISABLED
;
1711 bufsize
= encoding_buffer_size (&coding
, bytes
);
1712 buf
= (unsigned char *) xmalloc (bufsize
);
1713 encode_coding (&coding
, str
, buf
, bytes
, bufsize
);
1714 *text_bytes
= coding
.produced
;
1715 *stringp
= (charset_info
== 1
1716 || (!EQ (coding_system
, Qcompound_text
)
1717 && !EQ (coding_system
, Qcompound_text_with_extensions
)));
1722 /* Change the name of frame F to NAME. If NAME is nil, set F's name to
1725 If EXPLICIT is non-zero, that indicates that lisp code is setting the
1726 name; if NAME is a string, set F's name to NAME and set
1727 F->explicit_name; if NAME is Qnil, then clear F->explicit_name.
1729 If EXPLICIT is zero, that indicates that Emacs redisplay code is
1730 suggesting a new name, which lisp code should override; if
1731 F->explicit_name is set, ignore the new name; otherwise, set it. */
1734 x_set_name (f
, name
, explicit)
1739 /* Make sure that requests from lisp code override requests from
1740 Emacs redisplay code. */
1743 /* If we're switching from explicit to implicit, we had better
1744 update the mode lines and thereby update the title. */
1745 if (f
->explicit_name
&& NILP (name
))
1746 update_mode_lines
= 1;
1748 f
->explicit_name
= ! NILP (name
);
1750 else if (f
->explicit_name
)
1753 /* If NAME is nil, set the name to the x_id_name. */
1756 /* Check for no change needed in this very common case
1757 before we do any consing. */
1758 if (!strcmp (FRAME_X_DISPLAY_INFO (f
)->x_id_name
,
1761 name
= build_string (FRAME_X_DISPLAY_INFO (f
)->x_id_name
);
1764 CHECK_STRING (name
);
1766 /* Don't change the name if it's already NAME. */
1767 if (! NILP (Fstring_equal (name
, f
->name
)))
1772 /* For setting the frame title, the title parameter should override
1773 the name parameter. */
1774 if (! NILP (f
->title
))
1777 if (FRAME_X_WINDOW (f
))
1782 XTextProperty text
, icon
;
1784 Lisp_Object coding_system
;
1786 /* Note: Encoding strategy
1788 We encode NAME by compound-text and use "COMPOUND-TEXT" in
1789 text.encoding. But, there are non-internationalized window
1790 managers which don't support that encoding. So, if NAME
1791 contains only ASCII and 8859-1 characters, encode it by
1792 iso-latin-1, and use "STRING" in text.encoding hoping that
1793 such window manager at least analize this format correctly,
1794 i.e. treat 8-bit bytes as 8859-1 characters.
1796 We may also be able to use "UTF8_STRING" in text.encoding
1797 in the feature which can encode all Unicode characters.
1798 But, for the moment, there's no way to know that the
1799 current window manager supports it or not. */
1800 coding_system
= Qcompound_text
;
1801 text
.value
= x_encode_text (name
, coding_system
, 0, &bytes
, &stringp
);
1802 text
.encoding
= (stringp
? XA_STRING
1803 : FRAME_X_DISPLAY_INFO (f
)->Xatom_COMPOUND_TEXT
);
1805 text
.nitems
= bytes
;
1807 if (NILP (f
->icon_name
))
1813 /* See the above comment "Note: Encoding strategy". */
1814 icon
.value
= x_encode_text (f
->icon_name
, coding_system
, 0,
1816 icon
.encoding
= (stringp
? XA_STRING
1817 : FRAME_X_DISPLAY_INFO (f
)->Xatom_COMPOUND_TEXT
);
1819 icon
.nitems
= bytes
;
1822 gtk_window_set_title (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f
)),
1824 #else /* not USE_GTK */
1825 XSetWMName (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
), &text
);
1826 #endif /* not USE_GTK */
1828 XSetWMIconName (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
), &icon
);
1830 if (!NILP (f
->icon_name
)
1831 && icon
.value
!= (unsigned char *) SDATA (f
->icon_name
))
1833 if (text
.value
!= (unsigned char *) SDATA (name
))
1836 #else /* not HAVE_X11R4 */
1837 XSetIconName (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
1839 XStoreName (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
1841 #endif /* not HAVE_X11R4 */
1846 /* This function should be called when the user's lisp code has
1847 specified a name for the frame; the name will override any set by the
1850 x_explicitly_set_name (f
, arg
, oldval
)
1852 Lisp_Object arg
, oldval
;
1854 x_set_name (f
, arg
, 1);
1857 /* This function should be called by Emacs redisplay code to set the
1858 name; names set this way will never override names set by the user's
1861 x_implicitly_set_name (f
, arg
, oldval
)
1863 Lisp_Object arg
, oldval
;
1865 x_set_name (f
, arg
, 0);
1868 /* Change the title of frame F to NAME.
1869 If NAME is nil, use the frame name as the title.
1871 If EXPLICIT is non-zero, that indicates that lisp code is setting the
1872 name; if NAME is a string, set F's name to NAME and set
1873 F->explicit_name; if NAME is Qnil, then clear F->explicit_name.
1875 If EXPLICIT is zero, that indicates that Emacs redisplay code is
1876 suggesting a new name, which lisp code should override; if
1877 F->explicit_name is set, ignore the new name; otherwise, set it. */
1880 x_set_title (f
, name
, old_name
)
1882 Lisp_Object name
, old_name
;
1884 /* Don't change the title if it's already NAME. */
1885 if (EQ (name
, f
->title
))
1888 update_mode_lines
= 1;
1895 CHECK_STRING (name
);
1897 if (FRAME_X_WINDOW (f
))
1902 XTextProperty text
, icon
;
1904 Lisp_Object coding_system
;
1906 coding_system
= Qcompound_text
;
1907 /* See the comment "Note: Encoding strategy" in x_set_name. */
1908 text
.value
= x_encode_text (name
, coding_system
, 0, &bytes
, &stringp
);
1909 text
.encoding
= (stringp
? XA_STRING
1910 : FRAME_X_DISPLAY_INFO (f
)->Xatom_COMPOUND_TEXT
);
1912 text
.nitems
= bytes
;
1914 if (NILP (f
->icon_name
))
1920 /* See the comment "Note: Encoding strategy" in x_set_name. */
1921 icon
.value
= x_encode_text (f
->icon_name
, coding_system
, 0,
1923 icon
.encoding
= (stringp
? XA_STRING
1924 : FRAME_X_DISPLAY_INFO (f
)->Xatom_COMPOUND_TEXT
);
1926 icon
.nitems
= bytes
;
1930 gtk_window_set_title (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f
)),
1932 #else /* not USE_GTK */
1933 XSetWMName (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
), &text
);
1934 #endif /* not USE_GTK */
1936 XSetWMIconName (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
1939 if (!NILP (f
->icon_name
)
1940 && icon
.value
!= (unsigned char *) SDATA (f
->icon_name
))
1942 if (text
.value
!= (unsigned char *) SDATA (name
))
1945 #else /* not HAVE_X11R4 */
1946 XSetIconName (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
1948 XStoreName (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
1950 #endif /* not HAVE_X11R4 */
1956 x_set_scroll_bar_default_width (f
)
1959 int wid
= FONT_WIDTH (f
->output_data
.x
->font
);
1961 #ifdef USE_TOOLKIT_SCROLL_BARS
1962 /* A minimum width of 14 doesn't look good for toolkit scroll bars. */
1963 int width
= 16 + 2 * VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
1964 FRAME_SCROLL_BAR_COLS (f
) = (width
+ wid
- 1) / wid
;
1965 FRAME_SCROLL_BAR_PIXEL_WIDTH (f
) = width
;
1967 /* Make the actual width at least 14 pixels and a multiple of a
1969 FRAME_SCROLL_BAR_COLS (f
) = (14 + wid
- 1) / wid
;
1971 /* Use all of that space (aside from required margins) for the
1973 FRAME_SCROLL_BAR_PIXEL_WIDTH (f
) = 0;
1978 /* Record in frame F the specified or default value according to ALIST
1979 of the parameter named PROP (a Lisp symbol). If no value is
1980 specified for PROP, look for an X default for XPROP on the frame
1981 named NAME. If that is not found either, use the value DEFLT. */
1984 x_default_scroll_bar_color_parameter (f
, alist
, prop
, xprop
, xclass
,
1993 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
1996 tem
= x_get_arg (dpyinfo
, alist
, prop
, xprop
, xclass
, RES_TYPE_STRING
);
1997 if (EQ (tem
, Qunbound
))
1999 #ifdef USE_TOOLKIT_SCROLL_BARS
2001 /* See if an X resource for the scroll bar color has been
2003 tem
= display_x_get_resource (dpyinfo
,
2004 build_string (foreground_p
2008 build_string ("verticalScrollBar"),
2012 /* If nothing has been specified, scroll bars will use a
2013 toolkit-dependent default. Because these defaults are
2014 difficult to get at without actually creating a scroll
2015 bar, use nil to indicate that no color has been
2020 #else /* not USE_TOOLKIT_SCROLL_BARS */
2024 #endif /* not USE_TOOLKIT_SCROLL_BARS */
2027 x_set_frame_parameters (f
, Fcons (Fcons (prop
, tem
), Qnil
));
2033 #if !defined (HAVE_X11R4) && !defined (HAVE_XSETWMPROTOCOLS)
2036 XSetWMProtocols (dpy
, w
, protocols
, count
)
2043 prop
= XInternAtom (dpy
, "WM_PROTOCOLS", False
);
2044 if (prop
== None
) return False
;
2045 XChangeProperty (dpy
, w
, prop
, XA_ATOM
, 32, PropModeReplace
,
2046 (unsigned char *) protocols
, count
);
2049 #endif /* not HAVE_X11R4 && not HAVE_XSETWMPROTOCOLS */
2051 #ifdef USE_X_TOOLKIT
2053 /* If the WM_PROTOCOLS property does not already contain WM_TAKE_FOCUS,
2054 WM_DELETE_WINDOW, and WM_SAVE_YOURSELF, then add them. (They may
2055 already be present because of the toolkit (Motif adds some of them,
2056 for example, but Xt doesn't). */
2059 hack_wm_protocols (f
, widget
)
2063 Display
*dpy
= XtDisplay (widget
);
2064 Window w
= XtWindow (widget
);
2065 int need_delete
= 1;
2071 Atom type
, *atoms
= 0;
2073 unsigned long nitems
= 0;
2074 unsigned long bytes_after
;
2076 if ((XGetWindowProperty (dpy
, w
,
2077 FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_protocols
,
2078 (long)0, (long)100, False
, XA_ATOM
,
2079 &type
, &format
, &nitems
, &bytes_after
,
2080 (unsigned char **) &atoms
)
2082 && format
== 32 && type
== XA_ATOM
)
2086 if (atoms
[nitems
] == FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_delete_window
)
2088 else if (atoms
[nitems
] == FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_take_focus
)
2090 else if (atoms
[nitems
] == FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_save_yourself
)
2093 if (atoms
) XFree ((char *) atoms
);
2099 props
[count
++] = FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_delete_window
;
2101 props
[count
++] = FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_take_focus
;
2103 props
[count
++] = FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_save_yourself
;
2105 XChangeProperty (dpy
, w
, FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_protocols
,
2106 XA_ATOM
, 32, PropModeAppend
,
2107 (unsigned char *) props
, count
);
2115 /* Support routines for XIC (X Input Context). */
2119 static XFontSet xic_create_xfontset
P_ ((struct frame
*, char *));
2120 static XIMStyle best_xim_style
P_ ((XIMStyles
*, XIMStyles
*));
2123 /* Supported XIM styles, ordered by preferenc. */
2125 static XIMStyle supported_xim_styles
[] =
2127 XIMPreeditPosition
| XIMStatusArea
,
2128 XIMPreeditPosition
| XIMStatusNothing
,
2129 XIMPreeditPosition
| XIMStatusNone
,
2130 XIMPreeditNothing
| XIMStatusArea
,
2131 XIMPreeditNothing
| XIMStatusNothing
,
2132 XIMPreeditNothing
| XIMStatusNone
,
2133 XIMPreeditNone
| XIMStatusArea
,
2134 XIMPreeditNone
| XIMStatusNothing
,
2135 XIMPreeditNone
| XIMStatusNone
,
2140 /* Create an X fontset on frame F with base font name
2144 xic_create_xfontset (f
, base_fontname
)
2146 char *base_fontname
;
2149 char **missing_list
;
2153 xfs
= XCreateFontSet (FRAME_X_DISPLAY (f
),
2154 base_fontname
, &missing_list
,
2155 &missing_count
, &def_string
);
2157 XFreeStringList (missing_list
);
2159 /* No need to free def_string. */
2164 /* Value is the best input style, given user preferences USER (already
2165 checked to be supported by Emacs), and styles supported by the
2166 input method XIM. */
2169 best_xim_style (user
, xim
)
2175 for (i
= 0; i
< user
->count_styles
; ++i
)
2176 for (j
= 0; j
< xim
->count_styles
; ++j
)
2177 if (user
->supported_styles
[i
] == xim
->supported_styles
[j
])
2178 return user
->supported_styles
[i
];
2180 /* Return the default style. */
2181 return XIMPreeditNothing
| XIMStatusNothing
;
2184 /* Create XIC for frame F. */
2186 static XIMStyle xic_style
;
2189 create_frame_xic (f
)
2194 XFontSet xfs
= NULL
;
2199 xim
= FRAME_X_XIM (f
);
2204 XVaNestedList preedit_attr
;
2205 XVaNestedList status_attr
;
2206 char *base_fontname
;
2209 s_area
.x
= 0; s_area
.y
= 0; s_area
.width
= 1; s_area
.height
= 1;
2210 spot
.x
= 0; spot
.y
= 1;
2211 /* Create X fontset. */
2212 fontset
= FRAME_FONTSET (f
);
2214 base_fontname
= "-*-*-*-r-normal--14-*-*-*-*-*-*-*";
2217 /* Determine the base fontname from the ASCII font name of
2219 char *ascii_font
= (char *) SDATA (fontset_ascii (fontset
));
2220 char *p
= ascii_font
;
2223 for (i
= 0; *p
; p
++)
2226 /* As the font name doesn't conform to XLFD, we can't
2227 modify it to get a suitable base fontname for the
2229 base_fontname
= "-*-*-*-r-normal--14-*-*-*-*-*-*-*";
2232 int len
= strlen (ascii_font
) + 1;
2235 for (i
= 0, p
= ascii_font
; i
< 8; p
++)
2244 base_fontname
= (char *) alloca (len
);
2245 bzero (base_fontname
, len
);
2246 strcpy (base_fontname
, "-*-*-");
2247 bcopy (p1
, base_fontname
+ 5, p
- p1
);
2248 strcat (base_fontname
, "*-*-*-*-*-*-*");
2251 xfs
= xic_create_xfontset (f
, base_fontname
);
2253 /* Determine XIC style. */
2256 XIMStyles supported_list
;
2257 supported_list
.count_styles
= (sizeof supported_xim_styles
2258 / sizeof supported_xim_styles
[0]);
2259 supported_list
.supported_styles
= supported_xim_styles
;
2260 xic_style
= best_xim_style (&supported_list
,
2261 FRAME_X_XIM_STYLES (f
));
2264 preedit_attr
= XVaCreateNestedList (0,
2267 FRAME_FOREGROUND_PIXEL (f
),
2269 FRAME_BACKGROUND_PIXEL (f
),
2270 (xic_style
& XIMPreeditPosition
2275 status_attr
= XVaCreateNestedList (0,
2281 FRAME_FOREGROUND_PIXEL (f
),
2283 FRAME_BACKGROUND_PIXEL (f
),
2286 xic
= XCreateIC (xim
,
2287 XNInputStyle
, xic_style
,
2288 XNClientWindow
, FRAME_X_WINDOW(f
),
2289 XNFocusWindow
, FRAME_X_WINDOW(f
),
2290 XNStatusAttributes
, status_attr
,
2291 XNPreeditAttributes
, preedit_attr
,
2293 XFree (preedit_attr
);
2294 XFree (status_attr
);
2297 FRAME_XIC (f
) = xic
;
2298 FRAME_XIC_STYLE (f
) = xic_style
;
2299 FRAME_XIC_FONTSET (f
) = xfs
;
2303 /* Destroy XIC and free XIC fontset of frame F, if any. */
2309 if (FRAME_XIC (f
) == NULL
)
2312 XDestroyIC (FRAME_XIC (f
));
2313 if (FRAME_XIC_FONTSET (f
))
2314 XFreeFontSet (FRAME_X_DISPLAY (f
), FRAME_XIC_FONTSET (f
));
2316 FRAME_XIC (f
) = NULL
;
2317 FRAME_XIC_FONTSET (f
) = NULL
;
2321 /* Place preedit area for XIC of window W's frame to specified
2322 pixel position X/Y. X and Y are relative to window W. */
2325 xic_set_preeditarea (w
, x
, y
)
2329 struct frame
*f
= XFRAME (w
->frame
);
2333 spot
.x
= WINDOW_TO_FRAME_PIXEL_X (w
, x
);
2334 spot
.y
= WINDOW_TO_FRAME_PIXEL_Y (w
, y
) + FONT_BASE (FRAME_FONT (f
));
2335 attr
= XVaCreateNestedList (0, XNSpotLocation
, &spot
, NULL
);
2336 XSetICValues (FRAME_XIC (f
), XNPreeditAttributes
, attr
, NULL
);
2341 /* Place status area for XIC in bottom right corner of frame F.. */
2344 xic_set_statusarea (f
)
2347 XIC xic
= FRAME_XIC (f
);
2352 /* Negotiate geometry of status area. If input method has existing
2353 status area, use its current size. */
2354 area
.x
= area
.y
= area
.width
= area
.height
= 0;
2355 attr
= XVaCreateNestedList (0, XNAreaNeeded
, &area
, NULL
);
2356 XSetICValues (xic
, XNStatusAttributes
, attr
, NULL
);
2359 attr
= XVaCreateNestedList (0, XNAreaNeeded
, &needed
, NULL
);
2360 XGetICValues (xic
, XNStatusAttributes
, attr
, NULL
);
2363 if (needed
->width
== 0) /* Use XNArea instead of XNAreaNeeded */
2365 attr
= XVaCreateNestedList (0, XNArea
, &needed
, NULL
);
2366 XGetICValues (xic
, XNStatusAttributes
, attr
, NULL
);
2370 area
.width
= needed
->width
;
2371 area
.height
= needed
->height
;
2372 area
.x
= PIXEL_WIDTH (f
) - area
.width
- FRAME_INTERNAL_BORDER_WIDTH (f
);
2373 area
.y
= (PIXEL_HEIGHT (f
) - area
.height
2374 - FRAME_MENUBAR_HEIGHT (f
)
2375 - FRAME_TOOLBAR_HEIGHT (f
)
2376 - FRAME_INTERNAL_BORDER_WIDTH (f
));
2379 attr
= XVaCreateNestedList (0, XNArea
, &area
, NULL
);
2380 XSetICValues(xic
, XNStatusAttributes
, attr
, NULL
);
2385 /* Set X fontset for XIC of frame F, using base font name
2386 BASE_FONTNAME. Called when a new Emacs fontset is chosen. */
2389 xic_set_xfontset (f
, base_fontname
)
2391 char *base_fontname
;
2396 xfs
= xic_create_xfontset (f
, base_fontname
);
2398 attr
= XVaCreateNestedList (0, XNFontSet
, xfs
, NULL
);
2399 if (FRAME_XIC_STYLE (f
) & XIMPreeditPosition
)
2400 XSetICValues (FRAME_XIC (f
), XNPreeditAttributes
, attr
, NULL
);
2401 if (FRAME_XIC_STYLE (f
) & XIMStatusArea
)
2402 XSetICValues (FRAME_XIC (f
), XNStatusAttributes
, attr
, NULL
);
2405 if (FRAME_XIC_FONTSET (f
))
2406 XFreeFontSet (FRAME_X_DISPLAY (f
), FRAME_XIC_FONTSET (f
));
2407 FRAME_XIC_FONTSET (f
) = xfs
;
2410 #endif /* HAVE_X_I18N */
2414 #ifdef USE_X_TOOLKIT
2416 /* Create and set up the X widget for frame F. */
2419 x_window (f
, window_prompting
, minibuffer_only
)
2421 long window_prompting
;
2422 int minibuffer_only
;
2424 XClassHint class_hints
;
2425 XSetWindowAttributes attributes
;
2426 unsigned long attribute_mask
;
2427 Widget shell_widget
;
2429 Widget frame_widget
;
2435 /* Use the resource name as the top-level widget name
2436 for looking up resources. Make a non-Lisp copy
2437 for the window manager, so GC relocation won't bother it.
2439 Elsewhere we specify the window name for the window manager. */
2442 char *str
= (char *) SDATA (Vx_resource_name
);
2443 f
->namebuf
= (char *) xmalloc (strlen (str
) + 1);
2444 strcpy (f
->namebuf
, str
);
2448 XtSetArg (al
[ac
], XtNallowShellResize
, 1); ac
++;
2449 XtSetArg (al
[ac
], XtNinput
, 1); ac
++;
2450 XtSetArg (al
[ac
], XtNmappedWhenManaged
, 0); ac
++;
2451 XtSetArg (al
[ac
], XtNborderWidth
, f
->output_data
.x
->border_width
); ac
++;
2452 XtSetArg (al
[ac
], XtNvisual
, FRAME_X_VISUAL (f
)); ac
++;
2453 XtSetArg (al
[ac
], XtNdepth
, FRAME_X_DISPLAY_INFO (f
)->n_planes
); ac
++;
2454 XtSetArg (al
[ac
], XtNcolormap
, FRAME_X_COLORMAP (f
)); ac
++;
2455 shell_widget
= XtAppCreateShell (f
->namebuf
, EMACS_CLASS
,
2456 applicationShellWidgetClass
,
2457 FRAME_X_DISPLAY (f
), al
, ac
);
2459 f
->output_data
.x
->widget
= shell_widget
;
2460 /* maybe_set_screen_title_format (shell_widget); */
2462 pane_widget
= lw_create_widget ("main", "pane", widget_id_tick
++,
2463 (widget_value
*) NULL
,
2464 shell_widget
, False
,
2468 (lw_callback
) NULL
);
2471 XtSetArg (al
[ac
], XtNvisual
, FRAME_X_VISUAL (f
)); ac
++;
2472 XtSetArg (al
[ac
], XtNdepth
, FRAME_X_DISPLAY_INFO (f
)->n_planes
); ac
++;
2473 XtSetArg (al
[ac
], XtNcolormap
, FRAME_X_COLORMAP (f
)); ac
++;
2474 XtSetValues (pane_widget
, al
, ac
);
2475 f
->output_data
.x
->column_widget
= pane_widget
;
2477 /* mappedWhenManaged to false tells to the paned window to not map/unmap
2478 the emacs screen when changing menubar. This reduces flickering. */
2481 XtSetArg (al
[ac
], XtNmappedWhenManaged
, 0); ac
++;
2482 XtSetArg (al
[ac
], XtNshowGrip
, 0); ac
++;
2483 XtSetArg (al
[ac
], XtNallowResize
, 1); ac
++;
2484 XtSetArg (al
[ac
], XtNresizeToPreferred
, 1); ac
++;
2485 XtSetArg (al
[ac
], XtNemacsFrame
, f
); ac
++;
2486 XtSetArg (al
[ac
], XtNvisual
, FRAME_X_VISUAL (f
)); ac
++;
2487 XtSetArg (al
[ac
], XtNdepth
, FRAME_X_DISPLAY_INFO (f
)->n_planes
); ac
++;
2488 XtSetArg (al
[ac
], XtNcolormap
, FRAME_X_COLORMAP (f
)); ac
++;
2489 frame_widget
= XtCreateWidget (f
->namebuf
, emacsFrameClass
, pane_widget
,
2492 f
->output_data
.x
->edit_widget
= frame_widget
;
2494 XtManageChild (frame_widget
);
2496 /* Do some needed geometry management. */
2499 char *tem
, shell_position
[32];
2502 int extra_borders
= 0;
2504 = (f
->output_data
.x
->menubar_widget
2505 ? (f
->output_data
.x
->menubar_widget
->core
.height
2506 + f
->output_data
.x
->menubar_widget
->core
.border_width
)
2509 #if 0 /* Experimentally, we now get the right results
2510 for -geometry -0-0 without this. 24 Aug 96, rms. */
2511 if (FRAME_EXTERNAL_MENU_BAR (f
))
2514 XtVaGetValues (pane_widget
, XtNinternalBorderWidth
, &ibw
, NULL
);
2515 menubar_size
+= ibw
;
2519 f
->output_data
.x
->menubar_height
= menubar_size
;
2522 /* Motif seems to need this amount added to the sizes
2523 specified for the shell widget. The Athena/Lucid widgets don't.
2524 Both conclusions reached experimentally. -- rms. */
2525 XtVaGetValues (f
->output_data
.x
->edit_widget
, XtNinternalBorderWidth
,
2526 &extra_borders
, NULL
);
2530 /* Convert our geometry parameters into a geometry string
2532 Note that we do not specify here whether the position
2533 is a user-specified or program-specified one.
2534 We pass that information later, in x_wm_set_size_hints. */
2536 int left
= f
->output_data
.x
->left_pos
;
2537 int xneg
= window_prompting
& XNegative
;
2538 int top
= f
->output_data
.x
->top_pos
;
2539 int yneg
= window_prompting
& YNegative
;
2545 if (window_prompting
& USPosition
)
2546 sprintf (shell_position
, "=%dx%d%c%d%c%d",
2547 PIXEL_WIDTH (f
) + extra_borders
,
2548 PIXEL_HEIGHT (f
) + menubar_size
+ extra_borders
,
2549 (xneg
? '-' : '+'), left
,
2550 (yneg
? '-' : '+'), top
);
2552 sprintf (shell_position
, "=%dx%d",
2553 PIXEL_WIDTH (f
) + extra_borders
,
2554 PIXEL_HEIGHT (f
) + menubar_size
+ extra_borders
);
2557 len
= strlen (shell_position
) + 1;
2558 /* We don't free this because we don't know whether
2559 it is safe to free it while the frame exists.
2560 It isn't worth the trouble of arranging to free it
2561 when the frame is deleted. */
2562 tem
= (char *) xmalloc (len
);
2563 strncpy (tem
, shell_position
, len
);
2564 XtSetArg (al
[ac
], XtNgeometry
, tem
); ac
++;
2565 XtSetValues (shell_widget
, al
, ac
);
2568 XtManageChild (pane_widget
);
2569 XtRealizeWidget (shell_widget
);
2571 FRAME_X_WINDOW (f
) = XtWindow (frame_widget
);
2573 validate_x_resource_name ();
2575 class_hints
.res_name
= (char *) SDATA (Vx_resource_name
);
2576 class_hints
.res_class
= (char *) SDATA (Vx_resource_class
);
2577 XSetClassHint (FRAME_X_DISPLAY (f
), XtWindow (shell_widget
), &class_hints
);
2580 FRAME_XIC (f
) = NULL
;
2582 create_frame_xic (f
);
2586 f
->output_data
.x
->wm_hints
.input
= True
;
2587 f
->output_data
.x
->wm_hints
.flags
|= InputHint
;
2588 XSetWMHints (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2589 &f
->output_data
.x
->wm_hints
);
2591 hack_wm_protocols (f
, shell_widget
);
2594 XtAddEventHandler (shell_widget
, 0, True
, _XEditResCheckMessages
, 0);
2597 /* Do a stupid property change to force the server to generate a
2598 PropertyNotify event so that the event_stream server timestamp will
2599 be initialized to something relevant to the time we created the window.
2601 XChangeProperty (XtDisplay (frame_widget
), XtWindow (frame_widget
),
2602 FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_protocols
,
2603 XA_ATOM
, 32, PropModeAppend
,
2604 (unsigned char*) NULL
, 0);
2606 /* Make all the standard events reach the Emacs frame. */
2607 attributes
.event_mask
= STANDARD_EVENT_SET
;
2612 /* XIM server might require some X events. */
2613 unsigned long fevent
= NoEventMask
;
2614 XGetICValues(FRAME_XIC (f
), XNFilterEvents
, &fevent
, NULL
);
2615 attributes
.event_mask
|= fevent
;
2617 #endif /* HAVE_X_I18N */
2619 attribute_mask
= CWEventMask
;
2620 XChangeWindowAttributes (XtDisplay (shell_widget
), XtWindow (shell_widget
),
2621 attribute_mask
, &attributes
);
2623 XtMapWidget (frame_widget
);
2625 /* x_set_name normally ignores requests to set the name if the
2626 requested name is the same as the current name. This is the one
2627 place where that assumption isn't correct; f->name is set, but
2628 the X server hasn't been told. */
2631 int explicit = f
->explicit_name
;
2633 f
->explicit_name
= 0;
2636 x_set_name (f
, name
, explicit);
2639 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2640 f
->output_data
.x
->text_cursor
);
2644 /* This is a no-op, except under Motif. Make sure main areas are
2645 set to something reasonable, in case we get an error later. */
2646 lw_set_main_areas (pane_widget
, 0, frame_widget
);
2649 #else /* not USE_X_TOOLKIT */
2655 if (! xg_create_frame_widgets (f
))
2656 error ("Unable to create window");
2659 FRAME_XIC (f
) = NULL
;
2662 create_frame_xic (f
);
2665 /* XIM server might require some X events. */
2666 unsigned long fevent
= NoEventMask
;
2667 XGetICValues(FRAME_XIC (f
), XNFilterEvents
, &fevent
, NULL
);
2669 if (fevent
!= NoEventMask
)
2671 XSetWindowAttributes attributes
;
2672 XWindowAttributes wattr
;
2673 unsigned long attribute_mask
;
2675 XGetWindowAttributes (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2677 attributes
.event_mask
= wattr
.your_event_mask
| fevent
;
2678 attribute_mask
= CWEventMask
;
2679 XChangeWindowAttributes (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2680 attribute_mask
, &attributes
);
2688 #else /*! USE_GTK */
2689 /* Create and set up the X window for frame F. */
2696 XClassHint class_hints
;
2697 XSetWindowAttributes attributes
;
2698 unsigned long attribute_mask
;
2700 attributes
.background_pixel
= f
->output_data
.x
->background_pixel
;
2701 attributes
.border_pixel
= f
->output_data
.x
->border_pixel
;
2702 attributes
.bit_gravity
= StaticGravity
;
2703 attributes
.backing_store
= NotUseful
;
2704 attributes
.save_under
= True
;
2705 attributes
.event_mask
= STANDARD_EVENT_SET
;
2706 attributes
.colormap
= FRAME_X_COLORMAP (f
);
2707 attribute_mask
= (CWBackPixel
| CWBorderPixel
| CWBitGravity
| CWEventMask
2712 = XCreateWindow (FRAME_X_DISPLAY (f
),
2713 f
->output_data
.x
->parent_desc
,
2714 f
->output_data
.x
->left_pos
,
2715 f
->output_data
.x
->top_pos
,
2716 PIXEL_WIDTH (f
), PIXEL_HEIGHT (f
),
2717 f
->output_data
.x
->border_width
,
2718 CopyFromParent
, /* depth */
2719 InputOutput
, /* class */
2721 attribute_mask
, &attributes
);
2725 create_frame_xic (f
);
2728 /* XIM server might require some X events. */
2729 unsigned long fevent
= NoEventMask
;
2730 XGetICValues(FRAME_XIC (f
), XNFilterEvents
, &fevent
, NULL
);
2731 attributes
.event_mask
|= fevent
;
2732 attribute_mask
= CWEventMask
;
2733 XChangeWindowAttributes (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2734 attribute_mask
, &attributes
);
2737 #endif /* HAVE_X_I18N */
2739 validate_x_resource_name ();
2741 class_hints
.res_name
= (char *) SDATA (Vx_resource_name
);
2742 class_hints
.res_class
= (char *) SDATA (Vx_resource_class
);
2743 XSetClassHint (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), &class_hints
);
2745 /* The menubar is part of the ordinary display;
2746 it does not count in addition to the height of the window. */
2747 f
->output_data
.x
->menubar_height
= 0;
2749 /* This indicates that we use the "Passive Input" input model.
2750 Unless we do this, we don't get the Focus{In,Out} events that we
2751 need to draw the cursor correctly. Accursed bureaucrats.
2752 XWhipsAndChains (FRAME_X_DISPLAY (f), IronMaiden, &TheRack); */
2754 f
->output_data
.x
->wm_hints
.input
= True
;
2755 f
->output_data
.x
->wm_hints
.flags
|= InputHint
;
2756 XSetWMHints (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2757 &f
->output_data
.x
->wm_hints
);
2758 f
->output_data
.x
->wm_hints
.icon_pixmap
= None
;
2760 /* Request "save yourself" and "delete window" commands from wm. */
2763 protocols
[0] = FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_delete_window
;
2764 protocols
[1] = FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_save_yourself
;
2765 XSetWMProtocols (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), protocols
, 2);
2768 /* x_set_name normally ignores requests to set the name if the
2769 requested name is the same as the current name. This is the one
2770 place where that assumption isn't correct; f->name is set, but
2771 the X server hasn't been told. */
2774 int explicit = f
->explicit_name
;
2776 f
->explicit_name
= 0;
2779 x_set_name (f
, name
, explicit);
2782 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2783 f
->output_data
.x
->text_cursor
);
2787 if (FRAME_X_WINDOW (f
) == 0)
2788 error ("Unable to create window");
2791 #endif /* not USE_GTK */
2792 #endif /* not USE_X_TOOLKIT */
2794 /* Handle the icon stuff for this window. Perhaps later we might
2795 want an x_set_icon_position which can be called interactively as
2803 Lisp_Object icon_x
, icon_y
;
2804 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
2806 /* Set the position of the icon. Note that twm groups all
2807 icons in an icon window. */
2808 icon_x
= x_frame_get_and_record_arg (f
, parms
, Qicon_left
, 0, 0, RES_TYPE_NUMBER
);
2809 icon_y
= x_frame_get_and_record_arg (f
, parms
, Qicon_top
, 0, 0, RES_TYPE_NUMBER
);
2810 if (!EQ (icon_x
, Qunbound
) && !EQ (icon_y
, Qunbound
))
2812 CHECK_NUMBER (icon_x
);
2813 CHECK_NUMBER (icon_y
);
2815 else if (!EQ (icon_x
, Qunbound
) || !EQ (icon_y
, Qunbound
))
2816 error ("Both left and top icon corners of icon must be specified");
2820 if (! EQ (icon_x
, Qunbound
))
2821 x_wm_set_icon_position (f
, XINT (icon_x
), XINT (icon_y
));
2823 /* Start up iconic or window? */
2824 x_wm_set_window_state
2825 (f
, (EQ (x_get_arg (dpyinfo
, parms
, Qvisibility
, 0, 0, RES_TYPE_SYMBOL
),
2830 x_text_icon (f
, (char *) SDATA ((!NILP (f
->icon_name
)
2837 /* Make the GCs needed for this window, setting the
2838 background, border and mouse colors; also create the
2839 mouse cursor and the gray border tile. */
2841 static char cursor_bits
[] =
2843 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2844 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2845 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2846 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
2853 XGCValues gc_values
;
2857 /* Create the GCs of this frame.
2858 Note that many default values are used. */
2861 gc_values
.font
= f
->output_data
.x
->font
->fid
;
2862 gc_values
.foreground
= f
->output_data
.x
->foreground_pixel
;
2863 gc_values
.background
= f
->output_data
.x
->background_pixel
;
2864 gc_values
.line_width
= 0; /* Means 1 using fast algorithm. */
2865 f
->output_data
.x
->normal_gc
2866 = XCreateGC (FRAME_X_DISPLAY (f
),
2868 GCLineWidth
| GCFont
| GCForeground
| GCBackground
,
2871 /* Reverse video style. */
2872 gc_values
.foreground
= f
->output_data
.x
->background_pixel
;
2873 gc_values
.background
= f
->output_data
.x
->foreground_pixel
;
2874 f
->output_data
.x
->reverse_gc
2875 = XCreateGC (FRAME_X_DISPLAY (f
),
2877 GCFont
| GCForeground
| GCBackground
| GCLineWidth
,
2880 /* Cursor has cursor-color background, background-color foreground. */
2881 gc_values
.foreground
= f
->output_data
.x
->background_pixel
;
2882 gc_values
.background
= f
->output_data
.x
->cursor_pixel
;
2883 gc_values
.fill_style
= FillOpaqueStippled
;
2885 = XCreateBitmapFromData (FRAME_X_DISPLAY (f
),
2886 FRAME_X_DISPLAY_INFO (f
)->root_window
,
2887 cursor_bits
, 16, 16);
2888 f
->output_data
.x
->cursor_gc
2889 = XCreateGC (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2890 (GCFont
| GCForeground
| GCBackground
2891 | GCFillStyle
/* | GCStipple */ | GCLineWidth
),
2895 f
->output_data
.x
->white_relief
.gc
= 0;
2896 f
->output_data
.x
->black_relief
.gc
= 0;
2898 /* Create the gray border tile used when the pointer is not in
2899 the frame. Since this depends on the frame's pixel values,
2900 this must be done on a per-frame basis. */
2901 f
->output_data
.x
->border_tile
2902 = (XCreatePixmapFromBitmapData
2903 (FRAME_X_DISPLAY (f
), FRAME_X_DISPLAY_INFO (f
)->root_window
,
2904 gray_bits
, gray_width
, gray_height
,
2905 f
->output_data
.x
->foreground_pixel
,
2906 f
->output_data
.x
->background_pixel
,
2907 DefaultDepth (FRAME_X_DISPLAY (f
), FRAME_X_SCREEN_NUMBER (f
))));
2913 /* Free what was was allocated in x_make_gc. */
2919 Display
*dpy
= FRAME_X_DISPLAY (f
);
2923 if (f
->output_data
.x
->normal_gc
)
2925 XFreeGC (dpy
, f
->output_data
.x
->normal_gc
);
2926 f
->output_data
.x
->normal_gc
= 0;
2929 if (f
->output_data
.x
->reverse_gc
)
2931 XFreeGC (dpy
, f
->output_data
.x
->reverse_gc
);
2932 f
->output_data
.x
->reverse_gc
= 0;
2935 if (f
->output_data
.x
->cursor_gc
)
2937 XFreeGC (dpy
, f
->output_data
.x
->cursor_gc
);
2938 f
->output_data
.x
->cursor_gc
= 0;
2941 if (f
->output_data
.x
->border_tile
)
2943 XFreePixmap (dpy
, f
->output_data
.x
->border_tile
);
2944 f
->output_data
.x
->border_tile
= 0;
2951 /* Handler for signals raised during x_create_frame and
2952 x_create_top_frame. FRAME is the frame which is partially
2956 unwind_create_frame (frame
)
2959 struct frame
*f
= XFRAME (frame
);
2961 /* If frame is ``official'', nothing to do. */
2962 if (!CONSP (Vframe_list
) || !EQ (XCAR (Vframe_list
), frame
))
2965 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
2968 x_free_frame_resources (f
);
2970 /* Check that reference counts are indeed correct. */
2971 xassert (dpyinfo
->reference_count
== dpyinfo_refcount
);
2972 xassert (dpyinfo
->image_cache
->refcount
== image_cache_refcount
);
2980 DEFUN ("x-create-frame", Fx_create_frame
, Sx_create_frame
,
2982 doc
: /* Make a new X window, which is called a "frame" in Emacs terms.
2983 Returns an Emacs frame object.
2984 ALIST is an alist of frame parameters.
2985 If the parameters specify that the frame should not have a minibuffer,
2986 and do not specify a specific minibuffer window to use,
2987 then `default-minibuffer-frame' must be a frame whose minibuffer can
2988 be shared by the new frame.
2990 This function is an internal primitive--use `make-frame' instead. */)
2995 Lisp_Object frame
, tem
;
2997 int minibuffer_only
= 0;
2998 long window_prompting
= 0;
3000 int count
= SPECPDL_INDEX ();
3001 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
3002 Lisp_Object display
;
3003 struct x_display_info
*dpyinfo
= NULL
;
3009 /* Use this general default value to start with
3010 until we know if this frame has a specified name. */
3011 Vx_resource_name
= Vinvocation_name
;
3013 display
= x_get_arg (dpyinfo
, parms
, Qdisplay
, 0, 0, RES_TYPE_STRING
);
3014 if (EQ (display
, Qunbound
))
3016 dpyinfo
= check_x_display_info (display
);
3018 kb
= dpyinfo
->kboard
;
3020 kb
= &the_only_kboard
;
3023 name
= x_get_arg (dpyinfo
, parms
, Qname
, "name", "Name", RES_TYPE_STRING
);
3025 && ! EQ (name
, Qunbound
)
3027 error ("Invalid frame name--not a string or nil");
3030 Vx_resource_name
= name
;
3032 /* See if parent window is specified. */
3033 parent
= x_get_arg (dpyinfo
, parms
, Qparent_id
, NULL
, NULL
, RES_TYPE_NUMBER
);
3034 if (EQ (parent
, Qunbound
))
3036 if (! NILP (parent
))
3037 CHECK_NUMBER (parent
);
3039 /* make_frame_without_minibuffer can run Lisp code and garbage collect. */
3040 /* No need to protect DISPLAY because that's not used after passing
3041 it to make_frame_without_minibuffer. */
3043 GCPRO4 (parms
, parent
, name
, frame
);
3044 tem
= x_get_arg (dpyinfo
, parms
, Qminibuffer
, "minibuffer", "Minibuffer",
3046 if (EQ (tem
, Qnone
) || NILP (tem
))
3047 f
= make_frame_without_minibuffer (Qnil
, kb
, display
);
3048 else if (EQ (tem
, Qonly
))
3050 f
= make_minibuffer_frame ();
3051 minibuffer_only
= 1;
3053 else if (WINDOWP (tem
))
3054 f
= make_frame_without_minibuffer (tem
, kb
, display
);
3058 XSETFRAME (frame
, f
);
3060 /* Note that X Windows does support scroll bars. */
3061 FRAME_CAN_HAVE_SCROLL_BARS (f
) = 1;
3063 f
->output_method
= output_x_window
;
3064 f
->output_data
.x
= (struct x_output
*) xmalloc (sizeof (struct x_output
));
3065 bzero (f
->output_data
.x
, sizeof (struct x_output
));
3066 f
->output_data
.x
->icon_bitmap
= -1;
3067 f
->output_data
.x
->fontset
= -1;
3068 f
->output_data
.x
->scroll_bar_foreground_pixel
= -1;
3069 f
->output_data
.x
->scroll_bar_background_pixel
= -1;
3070 #ifdef USE_TOOLKIT_SCROLL_BARS
3071 f
->output_data
.x
->scroll_bar_top_shadow_pixel
= -1;
3072 f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
= -1;
3073 #endif /* USE_TOOLKIT_SCROLL_BARS */
3074 record_unwind_protect (unwind_create_frame
, frame
);
3077 = x_get_arg (dpyinfo
, parms
, Qicon_name
, "iconName", "Title",
3079 if (! STRINGP (f
->icon_name
))
3080 f
->icon_name
= Qnil
;
3082 FRAME_X_DISPLAY_INFO (f
) = dpyinfo
;
3084 image_cache_refcount
= FRAME_X_IMAGE_CACHE (f
)->refcount
;
3085 dpyinfo_refcount
= dpyinfo
->reference_count
;
3086 #endif /* GLYPH_DEBUG */
3088 FRAME_KBOARD (f
) = kb
;
3091 /* These colors will be set anyway later, but it's important
3092 to get the color reference counts right, so initialize them! */
3095 struct gcpro gcpro1
;
3097 /* Function x_decode_color can signal an error. Make
3098 sure to initialize color slots so that we won't try
3099 to free colors we haven't allocated. */
3100 f
->output_data
.x
->foreground_pixel
= -1;
3101 f
->output_data
.x
->background_pixel
= -1;
3102 f
->output_data
.x
->cursor_pixel
= -1;
3103 f
->output_data
.x
->cursor_foreground_pixel
= -1;
3104 f
->output_data
.x
->border_pixel
= -1;
3105 f
->output_data
.x
->mouse_pixel
= -1;
3107 black
= build_string ("black");
3109 f
->output_data
.x
->foreground_pixel
3110 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
3111 f
->output_data
.x
->background_pixel
3112 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
3113 f
->output_data
.x
->cursor_pixel
3114 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
3115 f
->output_data
.x
->cursor_foreground_pixel
3116 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
3117 f
->output_data
.x
->border_pixel
3118 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
3119 f
->output_data
.x
->mouse_pixel
3120 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
3124 /* Specify the parent under which to make this X window. */
3128 f
->output_data
.x
->parent_desc
= (Window
) XFASTINT (parent
);
3129 f
->output_data
.x
->explicit_parent
= 1;
3133 f
->output_data
.x
->parent_desc
= FRAME_X_DISPLAY_INFO (f
)->root_window
;
3134 f
->output_data
.x
->explicit_parent
= 0;
3137 /* Set the name; the functions to which we pass f expect the name to
3139 if (EQ (name
, Qunbound
) || NILP (name
))
3141 f
->name
= build_string (dpyinfo
->x_id_name
);
3142 f
->explicit_name
= 0;
3147 f
->explicit_name
= 1;
3148 /* use the frame's title when getting resources for this frame. */
3149 specbind (Qx_resource_name
, name
);
3152 /* Extract the window parameters from the supplied values
3153 that are needed to determine window geometry. */
3157 font
= x_get_arg (dpyinfo
, parms
, Qfont
, "font", "Font", RES_TYPE_STRING
);
3160 /* First, try whatever font the caller has specified. */
3163 tem
= Fquery_fontset (font
, Qnil
);
3165 font
= x_new_fontset (f
, SDATA (tem
));
3167 font
= x_new_font (f
, SDATA (font
));
3170 /* Try out a font which we hope has bold and italic variations. */
3171 if (!STRINGP (font
))
3172 font
= x_new_font (f
, "-adobe-courier-medium-r-*-*-*-120-*-*-*-*-iso8859-1");
3173 if (!STRINGP (font
))
3174 font
= x_new_font (f
, "-misc-fixed-medium-r-normal-*-*-140-*-*-c-*-iso8859-1");
3175 if (! STRINGP (font
))
3176 font
= x_new_font (f
, "-*-*-medium-r-normal-*-*-140-*-*-c-*-iso8859-1");
3177 if (! STRINGP (font
))
3178 /* This was formerly the first thing tried, but it finds too many fonts
3179 and takes too long. */
3180 font
= x_new_font (f
, "-*-*-medium-r-*-*-*-*-*-*-c-*-iso8859-1");
3181 /* If those didn't work, look for something which will at least work. */
3182 if (! STRINGP (font
))
3183 font
= x_new_font (f
, "-*-fixed-*-*-*-*-*-140-*-*-c-*-iso8859-1");
3185 if (! STRINGP (font
))
3186 font
= build_string ("fixed");
3188 x_default_parameter (f
, parms
, Qfont
, font
,
3189 "font", "Font", RES_TYPE_STRING
);
3193 /* Prevent lwlib/xlwmenu.c from crashing because of a bug
3194 whereby it fails to get any font. */
3195 xlwmenu_default_font
= f
->output_data
.x
->font
;
3198 x_default_parameter (f
, parms
, Qborder_width
, make_number (2),
3199 "borderWidth", "BorderWidth", RES_TYPE_NUMBER
);
3201 /* This defaults to 1 in order to match xterm. We recognize either
3202 internalBorderWidth or internalBorder (which is what xterm calls
3204 if (NILP (Fassq (Qinternal_border_width
, parms
)))
3208 value
= x_get_arg (dpyinfo
, parms
, Qinternal_border_width
,
3209 "internalBorder", "internalBorder", RES_TYPE_NUMBER
);
3210 if (! EQ (value
, Qunbound
))
3211 parms
= Fcons (Fcons (Qinternal_border_width
, value
),
3214 x_default_parameter (f
, parms
, Qinternal_border_width
, make_number (1),
3215 "internalBorderWidth", "internalBorderWidth",
3217 x_default_parameter (f
, parms
, Qvertical_scroll_bars
, Qleft
,
3218 "verticalScrollBars", "ScrollBars",
3221 /* Also do the stuff which must be set before the window exists. */
3222 x_default_parameter (f
, parms
, Qforeground_color
, build_string ("black"),
3223 "foreground", "Foreground", RES_TYPE_STRING
);
3224 x_default_parameter (f
, parms
, Qbackground_color
, build_string ("white"),
3225 "background", "Background", RES_TYPE_STRING
);
3226 x_default_parameter (f
, parms
, Qmouse_color
, build_string ("black"),
3227 "pointerColor", "Foreground", RES_TYPE_STRING
);
3228 x_default_parameter (f
, parms
, Qcursor_color
, build_string ("black"),
3229 "cursorColor", "Foreground", RES_TYPE_STRING
);
3230 x_default_parameter (f
, parms
, Qborder_color
, build_string ("black"),
3231 "borderColor", "BorderColor", RES_TYPE_STRING
);
3232 x_default_parameter (f
, parms
, Qscreen_gamma
, Qnil
,
3233 "screenGamma", "ScreenGamma", RES_TYPE_FLOAT
);
3234 x_default_parameter (f
, parms
, Qline_spacing
, Qnil
,
3235 "lineSpacing", "LineSpacing", RES_TYPE_NUMBER
);
3236 x_default_parameter (f
, parms
, Qleft_fringe
, Qnil
,
3237 "leftFringe", "LeftFringe", RES_TYPE_NUMBER
);
3238 x_default_parameter (f
, parms
, Qright_fringe
, Qnil
,
3239 "rightFringe", "RightFringe", RES_TYPE_NUMBER
);
3241 x_default_scroll_bar_color_parameter (f
, parms
, Qscroll_bar_foreground
,
3242 "scrollBarForeground",
3243 "ScrollBarForeground", 1);
3244 x_default_scroll_bar_color_parameter (f
, parms
, Qscroll_bar_background
,
3245 "scrollBarBackground",
3246 "ScrollBarBackground", 0);
3248 /* Init faces before x_default_parameter is called for scroll-bar
3249 parameters because that function calls x_set_scroll_bar_width,
3250 which calls change_frame_size, which calls Fset_window_buffer,
3251 which runs hooks, which call Fvertical_motion. At the end, we
3252 end up in init_iterator with a null face cache, which should not
3254 init_frame_faces (f
);
3256 x_default_parameter (f
, parms
, Qmenu_bar_lines
, make_number (1),
3257 "menuBar", "MenuBar", RES_TYPE_NUMBER
);
3258 x_default_parameter (f
, parms
, Qtool_bar_lines
, make_number (1),
3259 "toolBar", "ToolBar", RES_TYPE_NUMBER
);
3260 x_default_parameter (f
, parms
, Qbuffer_predicate
, Qnil
,
3261 "bufferPredicate", "BufferPredicate",
3263 x_default_parameter (f
, parms
, Qtitle
, Qnil
,
3264 "title", "Title", RES_TYPE_STRING
);
3265 x_default_parameter (f
, parms
, Qwait_for_wm
, Qt
,
3266 "waitForWM", "WaitForWM", RES_TYPE_BOOLEAN
);
3267 x_default_parameter (f
, parms
, Qfullscreen
, Qnil
,
3268 "fullscreen", "Fullscreen", RES_TYPE_SYMBOL
);
3270 f
->output_data
.x
->parent_desc
= FRAME_X_DISPLAY_INFO (f
)->root_window
;
3272 /* Compute the size of the X window. */
3273 window_prompting
= x_figure_window_size (f
, parms
, 1);
3275 tem
= x_get_arg (dpyinfo
, parms
, Qunsplittable
, 0, 0, RES_TYPE_BOOLEAN
);
3276 f
->no_split
= minibuffer_only
|| EQ (tem
, Qt
);
3278 /* Create the X widget or window. */
3279 #ifdef USE_X_TOOLKIT
3280 x_window (f
, window_prompting
, minibuffer_only
);
3288 /* Now consider the frame official. */
3289 FRAME_X_DISPLAY_INFO (f
)->reference_count
++;
3290 Vframe_list
= Fcons (frame
, Vframe_list
);
3292 /* We need to do this after creating the X window, so that the
3293 icon-creation functions can say whose icon they're describing. */
3294 x_default_parameter (f
, parms
, Qicon_type
, Qnil
,
3295 "bitmapIcon", "BitmapIcon", RES_TYPE_SYMBOL
);
3297 x_default_parameter (f
, parms
, Qauto_raise
, Qnil
,
3298 "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
3299 x_default_parameter (f
, parms
, Qauto_lower
, Qnil
,
3300 "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
3301 x_default_parameter (f
, parms
, Qcursor_type
, Qbox
,
3302 "cursorType", "CursorType", RES_TYPE_SYMBOL
);
3303 x_default_parameter (f
, parms
, Qscroll_bar_width
, Qnil
,
3304 "scrollBarWidth", "ScrollBarWidth",
3307 /* Dimensions, especially f->height, must be done via change_frame_size.
3308 Change will not be effected unless different from the current
3314 SET_FRAME_WIDTH (f
, 0);
3315 change_frame_size (f
, height
, width
, 1, 0, 0);
3317 /* Set up faces after all frame parameters are known. This call
3318 also merges in face attributes specified for new frames. If we
3319 don't do this, the `menu' face for instance won't have the right
3320 colors, and the menu bar won't appear in the specified colors for
3322 call1 (Qface_set_after_frame_default
, frame
);
3324 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
3325 /* Create the menu bar. */
3326 if (!minibuffer_only
&& FRAME_EXTERNAL_MENU_BAR (f
))
3328 /* If this signals an error, we haven't set size hints for the
3329 frame and we didn't make it visible. */
3330 initialize_frame_menubar (f
);
3333 /* This is a no-op, except under Motif where it arranges the
3334 main window for the widgets on it. */
3335 lw_set_main_areas (f
->output_data
.x
->column_widget
,
3336 f
->output_data
.x
->menubar_widget
,
3337 f
->output_data
.x
->edit_widget
);
3338 #endif /* not USE_GTK */
3340 #endif /* USE_X_TOOLKIT || USE_GTK */
3342 /* Tell the server what size and position, etc, we want, and how
3343 badly we want them. This should be done after we have the menu
3344 bar so that its size can be taken into account. */
3346 x_wm_set_size_hint (f
, window_prompting
, 0);
3349 /* Make the window appear on the frame and enable display, unless
3350 the caller says not to. However, with explicit parent, Emacs
3351 cannot control visibility, so don't try. */
3352 if (! f
->output_data
.x
->explicit_parent
)
3354 Lisp_Object visibility
;
3356 visibility
= x_get_arg (dpyinfo
, parms
, Qvisibility
, 0, 0,
3358 if (EQ (visibility
, Qunbound
))
3361 if (EQ (visibility
, Qicon
))
3362 x_iconify_frame (f
);
3363 else if (! NILP (visibility
))
3364 x_make_frame_visible (f
);
3366 /* Must have been Qnil. */
3372 /* Make sure windows on this frame appear in calls to next-window
3373 and similar functions. */
3374 Vwindow_list
= Qnil
;
3376 return unbind_to (count
, frame
);
3380 /* FRAME is used only to get a handle on the X display. We don't pass the
3381 display info directly because we're called from frame.c, which doesn't
3382 know about that structure. */
3385 x_get_focus_frame (frame
)
3386 struct frame
*frame
;
3388 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (frame
);
3390 if (! dpyinfo
->x_focus_frame
)
3393 XSETFRAME (xfocus
, dpyinfo
->x_focus_frame
);
3398 /* In certain situations, when the window manager follows a
3399 click-to-focus policy, there seems to be no way around calling
3400 XSetInputFocus to give another frame the input focus .
3402 In an ideal world, XSetInputFocus should generally be avoided so
3403 that applications don't interfere with the window manager's focus
3404 policy. But I think it's okay to use when it's clearly done
3405 following a user-command. */
3407 DEFUN ("x-focus-frame", Fx_focus_frame
, Sx_focus_frame
, 1, 1, 0,
3408 doc
: /* Set the input focus to FRAME.
3409 FRAME nil means use the selected frame. */)
3413 struct frame
*f
= check_x_frame (frame
);
3414 Display
*dpy
= FRAME_X_DISPLAY (f
);
3418 count
= x_catch_errors (dpy
);
3419 XSetInputFocus (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
3420 RevertToParent
, CurrentTime
);
3421 x_uncatch_errors (dpy
, count
);
3428 DEFUN ("xw-color-defined-p", Fxw_color_defined_p
, Sxw_color_defined_p
, 1, 2, 0,
3429 doc
: /* Internal function called by `color-defined-p', which see. */)
3431 Lisp_Object color
, frame
;
3434 FRAME_PTR f
= check_x_frame (frame
);
3436 CHECK_STRING (color
);
3438 if (x_defined_color (f
, SDATA (color
), &foo
, 0))
3444 DEFUN ("xw-color-values", Fxw_color_values
, Sxw_color_values
, 1, 2, 0,
3445 doc
: /* Internal function called by `color-values', which see. */)
3447 Lisp_Object color
, frame
;
3450 FRAME_PTR f
= check_x_frame (frame
);
3452 CHECK_STRING (color
);
3454 if (x_defined_color (f
, SDATA (color
), &foo
, 0))
3458 rgb
[0] = make_number (foo
.red
);
3459 rgb
[1] = make_number (foo
.green
);
3460 rgb
[2] = make_number (foo
.blue
);
3461 return Flist (3, rgb
);
3467 DEFUN ("xw-display-color-p", Fxw_display_color_p
, Sxw_display_color_p
, 0, 1, 0,
3468 doc
: /* Internal function called by `display-color-p', which see. */)
3470 Lisp_Object display
;
3472 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
3474 if (dpyinfo
->n_planes
<= 2)
3477 switch (dpyinfo
->visual
->class)
3490 DEFUN ("x-display-grayscale-p", Fx_display_grayscale_p
, Sx_display_grayscale_p
,
3492 doc
: /* Return t if the X display supports shades of gray.
3493 Note that color displays do support shades of gray.
3494 The optional argument DISPLAY specifies which display to ask about.
3495 DISPLAY should be either a frame or a display name (a string).
3496 If omitted or nil, that stands for the selected frame's display. */)
3498 Lisp_Object display
;
3500 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
3502 if (dpyinfo
->n_planes
<= 1)
3505 switch (dpyinfo
->visual
->class)
3520 DEFUN ("x-display-pixel-width", Fx_display_pixel_width
, Sx_display_pixel_width
,
3522 doc
: /* Returns the width in pixels of the X display DISPLAY.
3523 The optional argument DISPLAY specifies which display to ask about.
3524 DISPLAY should be either a frame or a display name (a string).
3525 If omitted or nil, that stands for the selected frame's display. */)
3527 Lisp_Object display
;
3529 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
3531 return make_number (dpyinfo
->width
);
3534 DEFUN ("x-display-pixel-height", Fx_display_pixel_height
,
3535 Sx_display_pixel_height
, 0, 1, 0,
3536 doc
: /* Returns the height in pixels of the X display DISPLAY.
3537 The optional argument DISPLAY specifies which display to ask about.
3538 DISPLAY should be either a frame or a display name (a string).
3539 If omitted or nil, that stands for the selected frame's display. */)
3541 Lisp_Object display
;
3543 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
3545 return make_number (dpyinfo
->height
);
3548 DEFUN ("x-display-planes", Fx_display_planes
, Sx_display_planes
,
3550 doc
: /* Returns the number of bitplanes of the X display DISPLAY.
3551 The optional argument DISPLAY specifies which display to ask about.
3552 DISPLAY should be either a frame or a display name (a string).
3553 If omitted or nil, that stands for the selected frame's display. */)
3555 Lisp_Object display
;
3557 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
3559 return make_number (dpyinfo
->n_planes
);
3562 DEFUN ("x-display-color-cells", Fx_display_color_cells
, Sx_display_color_cells
,
3564 doc
: /* Returns the number of color cells of the X display DISPLAY.
3565 The optional argument DISPLAY specifies which display to ask about.
3566 DISPLAY should be either a frame or a display name (a string).
3567 If omitted or nil, that stands for the selected frame's display. */)
3569 Lisp_Object display
;
3571 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
3573 return make_number (DisplayCells (dpyinfo
->display
,
3574 XScreenNumberOfScreen (dpyinfo
->screen
)));
3577 DEFUN ("x-server-max-request-size", Fx_server_max_request_size
,
3578 Sx_server_max_request_size
,
3580 doc
: /* Returns the maximum request size of the X server of display DISPLAY.
3581 The optional argument DISPLAY specifies which display to ask about.
3582 DISPLAY should be either a frame or a display name (a string).
3583 If omitted or nil, that stands for the selected frame's display. */)
3585 Lisp_Object display
;
3587 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
3589 return make_number (MAXREQUEST (dpyinfo
->display
));
3592 DEFUN ("x-server-vendor", Fx_server_vendor
, Sx_server_vendor
, 0, 1, 0,
3593 doc
: /* Returns the vendor ID string of the X server of display DISPLAY.
3594 The optional argument DISPLAY specifies which display to ask about.
3595 DISPLAY should be either a frame or a display name (a string).
3596 If omitted or nil, that stands for the selected frame's display. */)
3598 Lisp_Object display
;
3600 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
3601 char *vendor
= ServerVendor (dpyinfo
->display
);
3603 if (! vendor
) vendor
= "";
3604 return build_string (vendor
);
3607 DEFUN ("x-server-version", Fx_server_version
, Sx_server_version
, 0, 1, 0,
3608 doc
: /* Returns the version numbers of the X server of display DISPLAY.
3609 The value is a list of three integers: the major and minor
3610 version numbers of the X Protocol in use, and the vendor-specific release
3611 number. See also the function `x-server-vendor'.
3613 The optional argument DISPLAY specifies which display to ask about.
3614 DISPLAY should be either a frame or a display name (a string).
3615 If omitted or nil, that stands for the selected frame's display. */)
3617 Lisp_Object display
;
3619 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
3620 Display
*dpy
= dpyinfo
->display
;
3622 return Fcons (make_number (ProtocolVersion (dpy
)),
3623 Fcons (make_number (ProtocolRevision (dpy
)),
3624 Fcons (make_number (VendorRelease (dpy
)), Qnil
)));
3627 DEFUN ("x-display-screens", Fx_display_screens
, Sx_display_screens
, 0, 1, 0,
3628 doc
: /* Return the number of screens on the X server of display DISPLAY.
3629 The optional argument DISPLAY specifies which display to ask about.
3630 DISPLAY should be either a frame or a display name (a string).
3631 If omitted or nil, that stands for the selected frame's display. */)
3633 Lisp_Object display
;
3635 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
3637 return make_number (ScreenCount (dpyinfo
->display
));
3640 DEFUN ("x-display-mm-height", Fx_display_mm_height
, Sx_display_mm_height
, 0, 1, 0,
3641 doc
: /* Return the height in millimeters of the X display DISPLAY.
3642 The optional argument DISPLAY specifies which display to ask about.
3643 DISPLAY should be either a frame or a display name (a string).
3644 If omitted or nil, that stands for the selected frame's display. */)
3646 Lisp_Object display
;
3648 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
3650 return make_number (HeightMMOfScreen (dpyinfo
->screen
));
3653 DEFUN ("x-display-mm-width", Fx_display_mm_width
, Sx_display_mm_width
, 0, 1, 0,
3654 doc
: /* Return the width in millimeters of the X display DISPLAY.
3655 The optional argument DISPLAY specifies which display to ask about.
3656 DISPLAY should be either a frame or a display name (a string).
3657 If omitted or nil, that stands for the selected frame's display. */)
3659 Lisp_Object display
;
3661 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
3663 return make_number (WidthMMOfScreen (dpyinfo
->screen
));
3666 DEFUN ("x-display-backing-store", Fx_display_backing_store
,
3667 Sx_display_backing_store
, 0, 1, 0,
3668 doc
: /* Returns an indication of whether X display DISPLAY does backing store.
3669 The value may be `always', `when-mapped', or `not-useful'.
3670 The optional argument DISPLAY specifies which display to ask about.
3671 DISPLAY should be either a frame or a display name (a string).
3672 If omitted or nil, that stands for the selected frame's display. */)
3674 Lisp_Object display
;
3676 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
3679 switch (DoesBackingStore (dpyinfo
->screen
))
3682 result
= intern ("always");
3686 result
= intern ("when-mapped");
3690 result
= intern ("not-useful");
3694 error ("Strange value for BackingStore parameter of screen");
3701 DEFUN ("x-display-visual-class", Fx_display_visual_class
,
3702 Sx_display_visual_class
, 0, 1, 0,
3703 doc
: /* Return the visual class of the X display DISPLAY.
3704 The value is one of the symbols `static-gray', `gray-scale',
3705 `static-color', `pseudo-color', `true-color', or `direct-color'.
3707 The optional argument DISPLAY specifies which display to ask about.
3708 DISPLAY should be either a frame or a display name (a string).
3709 If omitted or nil, that stands for the selected frame's display. */)
3711 Lisp_Object display
;
3713 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
3716 switch (dpyinfo
->visual
->class)
3719 result
= intern ("static-gray");
3722 result
= intern ("gray-scale");
3725 result
= intern ("static-color");
3728 result
= intern ("pseudo-color");
3731 result
= intern ("true-color");
3734 result
= intern ("direct-color");
3737 error ("Display has an unknown visual class");
3744 DEFUN ("x-display-save-under", Fx_display_save_under
,
3745 Sx_display_save_under
, 0, 1, 0,
3746 doc
: /* Returns t if the X display DISPLAY supports the save-under feature.
3747 The optional argument DISPLAY specifies which display to ask about.
3748 DISPLAY should be either a frame or a display name (a string).
3749 If omitted or nil, that stands for the selected frame's display. */)
3751 Lisp_Object display
;
3753 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
3755 if (DoesSaveUnders (dpyinfo
->screen
) == True
)
3763 register struct frame
*f
;
3765 return PIXEL_WIDTH (f
);
3770 register struct frame
*f
;
3772 return PIXEL_HEIGHT (f
);
3777 register struct frame
*f
;
3779 return FONT_WIDTH (f
->output_data
.x
->font
);
3784 register struct frame
*f
;
3786 return f
->output_data
.x
->line_height
;
3791 register struct frame
*f
;
3793 return FRAME_X_DISPLAY_INFO (f
)->n_planes
;
3798 /************************************************************************
3800 ************************************************************************/
3803 /* Mapping visual names to visuals. */
3805 static struct visual_class
3812 {"StaticGray", StaticGray
},
3813 {"GrayScale", GrayScale
},
3814 {"StaticColor", StaticColor
},
3815 {"PseudoColor", PseudoColor
},
3816 {"TrueColor", TrueColor
},
3817 {"DirectColor", DirectColor
},
3822 #ifndef HAVE_XSCREENNUMBEROFSCREEN
3824 /* Value is the screen number of screen SCR. This is a substitute for
3825 the X function with the same name when that doesn't exist. */
3828 XScreenNumberOfScreen (scr
)
3829 register Screen
*scr
;
3831 Display
*dpy
= scr
->display
;
3834 for (i
= 0; i
< dpy
->nscreens
; ++i
)
3835 if (scr
== dpy
->screens
+ i
)
3841 #endif /* not HAVE_XSCREENNUMBEROFSCREEN */
3844 /* Select the visual that should be used on display DPYINFO. Set
3845 members of DPYINFO appropriately. Called from x_term_init. */
3848 select_visual (dpyinfo
)
3849 struct x_display_info
*dpyinfo
;
3851 Display
*dpy
= dpyinfo
->display
;
3852 Screen
*screen
= dpyinfo
->screen
;
3855 /* See if a visual is specified. */
3856 value
= display_x_get_resource (dpyinfo
,
3857 build_string ("visualClass"),
3858 build_string ("VisualClass"),
3860 if (STRINGP (value
))
3862 /* VALUE should be of the form CLASS-DEPTH, where CLASS is one
3863 of `PseudoColor', `TrueColor' etc. and DEPTH is the color
3864 depth, a decimal number. NAME is compared with case ignored. */
3865 char *s
= (char *) alloca (SBYTES (value
) + 1);
3870 strcpy (s
, SDATA (value
));
3871 dash
= index (s
, '-');
3874 dpyinfo
->n_planes
= atoi (dash
+ 1);
3878 /* We won't find a matching visual with depth 0, so that
3879 an error will be printed below. */
3880 dpyinfo
->n_planes
= 0;
3882 /* Determine the visual class. */
3883 for (i
= 0; visual_classes
[i
].name
; ++i
)
3884 if (xstricmp (s
, visual_classes
[i
].name
) == 0)
3886 class = visual_classes
[i
].class;
3890 /* Look up a matching visual for the specified class. */
3892 || !XMatchVisualInfo (dpy
, XScreenNumberOfScreen (screen
),
3893 dpyinfo
->n_planes
, class, &vinfo
))
3894 fatal ("Invalid visual specification `%s'", SDATA (value
));
3896 dpyinfo
->visual
= vinfo
.visual
;
3901 XVisualInfo
*vinfo
, vinfo_template
;
3903 dpyinfo
->visual
= DefaultVisualOfScreen (screen
);
3906 vinfo_template
.visualid
= XVisualIDFromVisual (dpyinfo
->visual
);
3908 vinfo_template
.visualid
= dpyinfo
->visual
->visualid
;
3910 vinfo_template
.screen
= XScreenNumberOfScreen (screen
);
3911 vinfo
= XGetVisualInfo (dpy
, VisualIDMask
| VisualScreenMask
,
3912 &vinfo_template
, &n_visuals
);
3914 fatal ("Can't get proper X visual info");
3916 dpyinfo
->n_planes
= vinfo
->depth
;
3917 XFree ((char *) vinfo
);
3922 /* Return the X display structure for the display named NAME.
3923 Open a new connection if necessary. */
3925 struct x_display_info
*
3926 x_display_info_for_name (name
)
3930 struct x_display_info
*dpyinfo
;
3932 CHECK_STRING (name
);
3934 if (! EQ (Vwindow_system
, intern ("x")))
3935 error ("Not using X Windows");
3937 for (dpyinfo
= x_display_list
, names
= x_display_name_list
;
3939 dpyinfo
= dpyinfo
->next
, names
= XCDR (names
))
3942 tem
= Fstring_equal (XCAR (XCAR (names
)), name
);
3947 /* Use this general default value to start with. */
3948 Vx_resource_name
= Vinvocation_name
;
3950 validate_x_resource_name ();
3952 dpyinfo
= x_term_init (name
, (char *)0,
3953 (char *) SDATA (Vx_resource_name
));
3956 error ("Cannot connect to X server %s", SDATA (name
));
3959 XSETFASTINT (Vwindow_system_version
, 11);
3965 DEFUN ("x-open-connection", Fx_open_connection
, Sx_open_connection
,
3967 doc
: /* Open a connection to an X server.
3968 DISPLAY is the name of the display to connect to.
3969 Optional second arg XRM-STRING is a string of resources in xrdb format.
3970 If the optional third arg MUST-SUCCEED is non-nil,
3971 terminate Emacs if we can't open the connection. */)
3972 (display
, xrm_string
, must_succeed
)
3973 Lisp_Object display
, xrm_string
, must_succeed
;
3975 unsigned char *xrm_option
;
3976 struct x_display_info
*dpyinfo
;
3978 CHECK_STRING (display
);
3979 if (! NILP (xrm_string
))
3980 CHECK_STRING (xrm_string
);
3982 if (! EQ (Vwindow_system
, intern ("x")))
3983 error ("Not using X Windows");
3985 if (! NILP (xrm_string
))
3986 xrm_option
= (unsigned char *) SDATA (xrm_string
);
3988 xrm_option
= (unsigned char *) 0;
3990 validate_x_resource_name ();
3992 /* This is what opens the connection and sets x_current_display.
3993 This also initializes many symbols, such as those used for input. */
3994 dpyinfo
= x_term_init (display
, xrm_option
,
3995 (char *) SDATA (Vx_resource_name
));
3999 if (!NILP (must_succeed
))
4000 fatal ("Cannot connect to X server %s.\n\
4001 Check the DISPLAY environment variable or use `-d'.\n\
4002 Also use the `xauth' program to verify that you have the proper\n\
4003 authorization information needed to connect the X server.\n\
4004 An insecure way to solve the problem may be to use `xhost'.\n",
4007 error ("Cannot connect to X server %s", SDATA (display
));
4012 XSETFASTINT (Vwindow_system_version
, 11);
4016 DEFUN ("x-close-connection", Fx_close_connection
,
4017 Sx_close_connection
, 1, 1, 0,
4018 doc
: /* Close the connection to DISPLAY's X server.
4019 For DISPLAY, specify either a frame or a display name (a string).
4020 If DISPLAY is nil, that stands for the selected frame's display. */)
4022 Lisp_Object display
;
4024 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
4027 if (dpyinfo
->reference_count
> 0)
4028 error ("Display still has frames on it");
4031 /* Free the fonts in the font table. */
4032 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
4033 if (dpyinfo
->font_table
[i
].name
)
4035 if (dpyinfo
->font_table
[i
].name
!= dpyinfo
->font_table
[i
].full_name
)
4036 xfree (dpyinfo
->font_table
[i
].full_name
);
4037 xfree (dpyinfo
->font_table
[i
].name
);
4038 XFreeFont (dpyinfo
->display
, dpyinfo
->font_table
[i
].font
);
4041 x_destroy_all_bitmaps (dpyinfo
);
4042 XSetCloseDownMode (dpyinfo
->display
, DestroyAll
);
4044 #ifdef USE_X_TOOLKIT
4045 XtCloseDisplay (dpyinfo
->display
);
4047 XCloseDisplay (dpyinfo
->display
);
4050 x_delete_display (dpyinfo
);
4056 DEFUN ("x-display-list", Fx_display_list
, Sx_display_list
, 0, 0, 0,
4057 doc
: /* Return the list of display names that Emacs has connections to. */)
4060 Lisp_Object tail
, result
;
4063 for (tail
= x_display_name_list
; ! NILP (tail
); tail
= XCDR (tail
))
4064 result
= Fcons (XCAR (XCAR (tail
)), result
);
4069 DEFUN ("x-synchronize", Fx_synchronize
, Sx_synchronize
, 1, 2, 0,
4070 doc
: /* If ON is non-nil, report X errors as soon as the erring request is made.
4071 If ON is nil, allow buffering of requests.
4072 Turning on synchronization prohibits the Xlib routines from buffering
4073 requests and seriously degrades performance, but makes debugging much
4075 The optional second argument DISPLAY specifies which display to act on.
4076 DISPLAY should be either a frame or a display name (a string).
4077 If DISPLAY is omitted or nil, that stands for the selected frame's display. */)
4079 Lisp_Object display
, on
;
4081 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
4083 XSynchronize (dpyinfo
->display
, !EQ (on
, Qnil
));
4088 /* Wait for responses to all X commands issued so far for frame F. */
4095 XSync (FRAME_X_DISPLAY (f
), False
);
4100 /***********************************************************************
4102 ***********************************************************************/
4104 /* Value is the number of elements of vector VECTOR. */
4106 #define DIM(VECTOR) (sizeof (VECTOR) / sizeof *(VECTOR))
4108 /* List of supported image types. Use define_image_type to add new
4109 types. Use lookup_image_type to find a type for a given symbol. */
4111 static struct image_type
*image_types
;
4113 /* The symbol `image' which is the car of the lists used to represent
4116 extern Lisp_Object Qimage
;
4118 /* The symbol `xbm' which is used as the type symbol for XBM images. */
4124 extern Lisp_Object QCwidth
, QCheight
, QCforeground
, QCbackground
, QCfile
;
4125 extern Lisp_Object QCdata
, QCtype
;
4126 Lisp_Object QCascent
, QCmargin
, QCrelief
;
4127 Lisp_Object QCconversion
, QCcolor_symbols
, QCheuristic_mask
;
4128 Lisp_Object QCindex
, QCmatrix
, QCcolor_adjustment
, QCmask
;
4130 /* Other symbols. */
4132 Lisp_Object Qlaplace
, Qemboss
, Qedge_detection
, Qheuristic
;
4134 /* Time in seconds after which images should be removed from the cache
4135 if not displayed. */
4137 Lisp_Object Vimage_cache_eviction_delay
;
4139 /* Function prototypes. */
4141 static void define_image_type
P_ ((struct image_type
*type
));
4142 static struct image_type
*lookup_image_type
P_ ((Lisp_Object symbol
));
4143 static void image_error
P_ ((char *format
, Lisp_Object
, Lisp_Object
));
4144 static void x_laplace
P_ ((struct frame
*, struct image
*));
4145 static void x_emboss
P_ ((struct frame
*, struct image
*));
4146 static int x_build_heuristic_mask
P_ ((struct frame
*, struct image
*,
4150 /* Define a new image type from TYPE. This adds a copy of TYPE to
4151 image_types and adds the symbol *TYPE->type to Vimage_types. */
4154 define_image_type (type
)
4155 struct image_type
*type
;
4157 /* Make a copy of TYPE to avoid a bus error in a dumped Emacs.
4158 The initialized data segment is read-only. */
4159 struct image_type
*p
= (struct image_type
*) xmalloc (sizeof *p
);
4160 bcopy (type
, p
, sizeof *p
);
4161 p
->next
= image_types
;
4163 Vimage_types
= Fcons (*p
->type
, Vimage_types
);
4167 /* Look up image type SYMBOL, and return a pointer to its image_type
4168 structure. Value is null if SYMBOL is not a known image type. */
4170 static INLINE
struct image_type
*
4171 lookup_image_type (symbol
)
4174 struct image_type
*type
;
4176 for (type
= image_types
; type
; type
= type
->next
)
4177 if (EQ (symbol
, *type
->type
))
4184 /* Value is non-zero if OBJECT is a valid Lisp image specification. A
4185 valid image specification is a list whose car is the symbol
4186 `image', and whose rest is a property list. The property list must
4187 contain a value for key `:type'. That value must be the name of a
4188 supported image type. The rest of the property list depends on the
4192 valid_image_p (object
)
4197 if (CONSP (object
) && EQ (XCAR (object
), Qimage
))
4201 for (tem
= XCDR (object
); CONSP (tem
); tem
= XCDR (tem
))
4202 if (EQ (XCAR (tem
), QCtype
))
4205 if (CONSP (tem
) && SYMBOLP (XCAR (tem
)))
4207 struct image_type
*type
;
4208 type
= lookup_image_type (XCAR (tem
));
4210 valid_p
= type
->valid_p (object
);
4221 /* Log error message with format string FORMAT and argument ARG.
4222 Signaling an error, e.g. when an image cannot be loaded, is not a
4223 good idea because this would interrupt redisplay, and the error
4224 message display would lead to another redisplay. This function
4225 therefore simply displays a message. */
4228 image_error (format
, arg1
, arg2
)
4230 Lisp_Object arg1
, arg2
;
4232 add_to_log (format
, arg1
, arg2
);
4237 /***********************************************************************
4238 Image specifications
4239 ***********************************************************************/
4241 enum image_value_type
4243 IMAGE_DONT_CHECK_VALUE_TYPE
,
4245 IMAGE_STRING_OR_NIL_VALUE
,
4247 IMAGE_POSITIVE_INTEGER_VALUE
,
4248 IMAGE_POSITIVE_INTEGER_VALUE_OR_PAIR
,
4249 IMAGE_NON_NEGATIVE_INTEGER_VALUE
,
4251 IMAGE_INTEGER_VALUE
,
4252 IMAGE_FUNCTION_VALUE
,
4257 /* Structure used when parsing image specifications. */
4259 struct image_keyword
4261 /* Name of keyword. */
4264 /* The type of value allowed. */
4265 enum image_value_type type
;
4267 /* Non-zero means key must be present. */
4270 /* Used to recognize duplicate keywords in a property list. */
4273 /* The value that was found. */
4278 static int parse_image_spec
P_ ((Lisp_Object
, struct image_keyword
*,
4280 static Lisp_Object image_spec_value
P_ ((Lisp_Object
, Lisp_Object
, int *));
4283 /* Parse image spec SPEC according to KEYWORDS. A valid image spec
4284 has the format (image KEYWORD VALUE ...). One of the keyword/
4285 value pairs must be `:type TYPE'. KEYWORDS is a vector of
4286 image_keywords structures of size NKEYWORDS describing other
4287 allowed keyword/value pairs. Value is non-zero if SPEC is valid. */
4290 parse_image_spec (spec
, keywords
, nkeywords
, type
)
4292 struct image_keyword
*keywords
;
4299 if (!CONSP (spec
) || !EQ (XCAR (spec
), Qimage
))
4302 plist
= XCDR (spec
);
4303 while (CONSP (plist
))
4305 Lisp_Object key
, value
;
4307 /* First element of a pair must be a symbol. */
4309 plist
= XCDR (plist
);
4313 /* There must follow a value. */
4316 value
= XCAR (plist
);
4317 plist
= XCDR (plist
);
4319 /* Find key in KEYWORDS. Error if not found. */
4320 for (i
= 0; i
< nkeywords
; ++i
)
4321 if (strcmp (keywords
[i
].name
, SDATA (SYMBOL_NAME (key
))) == 0)
4327 /* Record that we recognized the keyword. If a keywords
4328 was found more than once, it's an error. */
4329 keywords
[i
].value
= value
;
4330 ++keywords
[i
].count
;
4332 if (keywords
[i
].count
> 1)
4335 /* Check type of value against allowed type. */
4336 switch (keywords
[i
].type
)
4338 case IMAGE_STRING_VALUE
:
4339 if (!STRINGP (value
))
4343 case IMAGE_STRING_OR_NIL_VALUE
:
4344 if (!STRINGP (value
) && !NILP (value
))
4348 case IMAGE_SYMBOL_VALUE
:
4349 if (!SYMBOLP (value
))
4353 case IMAGE_POSITIVE_INTEGER_VALUE
:
4354 if (!INTEGERP (value
) || XINT (value
) <= 0)
4358 case IMAGE_POSITIVE_INTEGER_VALUE_OR_PAIR
:
4359 if (INTEGERP (value
) && XINT (value
) >= 0)
4362 && INTEGERP (XCAR (value
)) && INTEGERP (XCDR (value
))
4363 && XINT (XCAR (value
)) >= 0 && XINT (XCDR (value
)) >= 0)
4367 case IMAGE_ASCENT_VALUE
:
4368 if (SYMBOLP (value
) && EQ (value
, Qcenter
))
4370 else if (INTEGERP (value
)
4371 && XINT (value
) >= 0
4372 && XINT (value
) <= 100)
4376 case IMAGE_NON_NEGATIVE_INTEGER_VALUE
:
4377 if (!INTEGERP (value
) || XINT (value
) < 0)
4381 case IMAGE_DONT_CHECK_VALUE_TYPE
:
4384 case IMAGE_FUNCTION_VALUE
:
4385 value
= indirect_function (value
);
4387 || COMPILEDP (value
)
4388 || (CONSP (value
) && EQ (XCAR (value
), Qlambda
)))
4392 case IMAGE_NUMBER_VALUE
:
4393 if (!INTEGERP (value
) && !FLOATP (value
))
4397 case IMAGE_INTEGER_VALUE
:
4398 if (!INTEGERP (value
))
4402 case IMAGE_BOOL_VALUE
:
4403 if (!NILP (value
) && !EQ (value
, Qt
))
4412 if (EQ (key
, QCtype
) && !EQ (type
, value
))
4416 /* Check that all mandatory fields are present. */
4417 for (i
= 0; i
< nkeywords
; ++i
)
4418 if (keywords
[i
].mandatory_p
&& keywords
[i
].count
== 0)
4421 return NILP (plist
);
4425 /* Return the value of KEY in image specification SPEC. Value is nil
4426 if KEY is not present in SPEC. if FOUND is not null, set *FOUND
4427 to 1 if KEY was found in SPEC, set it to 0 otherwise. */
4430 image_spec_value (spec
, key
, found
)
4431 Lisp_Object spec
, key
;
4436 xassert (valid_image_p (spec
));
4438 for (tail
= XCDR (spec
);
4439 CONSP (tail
) && CONSP (XCDR (tail
));
4440 tail
= XCDR (XCDR (tail
)))
4442 if (EQ (XCAR (tail
), key
))
4446 return XCAR (XCDR (tail
));
4456 DEFUN ("image-size", Fimage_size
, Simage_size
, 1, 3, 0,
4457 doc
: /* Return the size of image SPEC as pair (WIDTH . HEIGHT).
4458 PIXELS non-nil means return the size in pixels, otherwise return the
4459 size in canonical character units.
4460 FRAME is the frame on which the image will be displayed. FRAME nil
4461 or omitted means use the selected frame. */)
4462 (spec
, pixels
, frame
)
4463 Lisp_Object spec
, pixels
, frame
;
4468 if (valid_image_p (spec
))
4470 struct frame
*f
= check_x_frame (frame
);
4471 int id
= lookup_image (f
, spec
);
4472 struct image
*img
= IMAGE_FROM_ID (f
, id
);
4473 int width
= img
->width
+ 2 * img
->hmargin
;
4474 int height
= img
->height
+ 2 * img
->vmargin
;
4477 size
= Fcons (make_float ((double) width
/ CANON_X_UNIT (f
)),
4478 make_float ((double) height
/ CANON_Y_UNIT (f
)));
4480 size
= Fcons (make_number (width
), make_number (height
));
4483 error ("Invalid image specification");
4489 DEFUN ("image-mask-p", Fimage_mask_p
, Simage_mask_p
, 1, 2, 0,
4490 doc
: /* Return t if image SPEC has a mask bitmap.
4491 FRAME is the frame on which the image will be displayed. FRAME nil
4492 or omitted means use the selected frame. */)
4494 Lisp_Object spec
, frame
;
4499 if (valid_image_p (spec
))
4501 struct frame
*f
= check_x_frame (frame
);
4502 int id
= lookup_image (f
, spec
);
4503 struct image
*img
= IMAGE_FROM_ID (f
, id
);
4508 error ("Invalid image specification");
4515 /***********************************************************************
4516 Image type independent image structures
4517 ***********************************************************************/
4519 static struct image
*make_image
P_ ((Lisp_Object spec
, unsigned hash
));
4520 static void free_image
P_ ((struct frame
*f
, struct image
*img
));
4523 /* Allocate and return a new image structure for image specification
4524 SPEC. SPEC has a hash value of HASH. */
4526 static struct image
*
4527 make_image (spec
, hash
)
4531 struct image
*img
= (struct image
*) xmalloc (sizeof *img
);
4533 xassert (valid_image_p (spec
));
4534 bzero (img
, sizeof *img
);
4535 img
->type
= lookup_image_type (image_spec_value (spec
, QCtype
, NULL
));
4536 xassert (img
->type
!= NULL
);
4538 img
->data
.lisp_val
= Qnil
;
4539 img
->ascent
= DEFAULT_IMAGE_ASCENT
;
4545 /* Free image IMG which was used on frame F, including its resources. */
4554 struct image_cache
*c
= FRAME_X_IMAGE_CACHE (f
);
4556 /* Remove IMG from the hash table of its cache. */
4558 img
->prev
->next
= img
->next
;
4560 c
->buckets
[img
->hash
% IMAGE_CACHE_BUCKETS_SIZE
] = img
->next
;
4563 img
->next
->prev
= img
->prev
;
4565 c
->images
[img
->id
] = NULL
;
4567 /* Free resources, then free IMG. */
4568 img
->type
->free (f
, img
);
4574 /* Prepare image IMG for display on frame F. Must be called before
4575 drawing an image. */
4578 prepare_image_for_display (f
, img
)
4584 /* We're about to display IMG, so set its timestamp to `now'. */
4586 img
->timestamp
= EMACS_SECS (t
);
4588 /* If IMG doesn't have a pixmap yet, load it now, using the image
4589 type dependent loader function. */
4590 if (img
->pixmap
== None
&& !img
->load_failed_p
)
4591 img
->load_failed_p
= img
->type
->load (f
, img
) == 0;
4595 /* Value is the number of pixels for the ascent of image IMG when
4596 drawn in face FACE. */
4599 image_ascent (img
, face
)
4603 int height
= img
->height
+ img
->vmargin
;
4606 if (img
->ascent
== CENTERED_IMAGE_ASCENT
)
4609 /* This expression is arranged so that if the image can't be
4610 exactly centered, it will be moved slightly up. This is
4611 because a typical font is `top-heavy' (due to the presence
4612 uppercase letters), so the image placement should err towards
4613 being top-heavy too. It also just generally looks better. */
4614 ascent
= (height
+ face
->font
->ascent
- face
->font
->descent
+ 1) / 2;
4616 ascent
= height
/ 2;
4619 ascent
= height
* img
->ascent
/ 100.0;
4625 /* Image background colors. */
4627 static unsigned long
4628 four_corners_best (ximg
, width
, height
)
4630 unsigned long width
, height
;
4632 unsigned long corners
[4], best
;
4635 /* Get the colors at the corners of ximg. */
4636 corners
[0] = XGetPixel (ximg
, 0, 0);
4637 corners
[1] = XGetPixel (ximg
, width
- 1, 0);
4638 corners
[2] = XGetPixel (ximg
, width
- 1, height
- 1);
4639 corners
[3] = XGetPixel (ximg
, 0, height
- 1);
4641 /* Choose the most frequently found color as background. */
4642 for (i
= best_count
= 0; i
< 4; ++i
)
4646 for (j
= n
= 0; j
< 4; ++j
)
4647 if (corners
[i
] == corners
[j
])
4651 best
= corners
[i
], best_count
= n
;
4657 /* Return the `background' field of IMG. If IMG doesn't have one yet,
4658 it is guessed heuristically. If non-zero, XIMG is an existing XImage
4659 object to use for the heuristic. */
4662 image_background (img
, f
, ximg
)
4667 if (! img
->background_valid
)
4668 /* IMG doesn't have a background yet, try to guess a reasonable value. */
4670 int free_ximg
= !ximg
;
4673 ximg
= XGetImage (FRAME_X_DISPLAY (f
), img
->pixmap
,
4674 0, 0, img
->width
, img
->height
, ~0, ZPixmap
);
4676 img
->background
= four_corners_best (ximg
, img
->width
, img
->height
);
4679 XDestroyImage (ximg
);
4681 img
->background_valid
= 1;
4684 return img
->background
;
4687 /* Return the `background_transparent' field of IMG. If IMG doesn't
4688 have one yet, it is guessed heuristically. If non-zero, MASK is an
4689 existing XImage object to use for the heuristic. */
4692 image_background_transparent (img
, f
, mask
)
4697 if (! img
->background_transparent_valid
)
4698 /* IMG doesn't have a background yet, try to guess a reasonable value. */
4702 int free_mask
= !mask
;
4705 mask
= XGetImage (FRAME_X_DISPLAY (f
), img
->mask
,
4706 0, 0, img
->width
, img
->height
, ~0, ZPixmap
);
4708 img
->background_transparent
4709 = !four_corners_best (mask
, img
->width
, img
->height
);
4712 XDestroyImage (mask
);
4715 img
->background_transparent
= 0;
4717 img
->background_transparent_valid
= 1;
4720 return img
->background_transparent
;
4724 /***********************************************************************
4725 Helper functions for X image types
4726 ***********************************************************************/
4728 static void x_clear_image_1
P_ ((struct frame
*, struct image
*, int,
4730 static void x_clear_image
P_ ((struct frame
*f
, struct image
*img
));
4731 static unsigned long x_alloc_image_color
P_ ((struct frame
*f
,
4733 Lisp_Object color_name
,
4734 unsigned long dflt
));
4737 /* Clear X resources of image IMG on frame F. PIXMAP_P non-zero means
4738 free the pixmap if any. MASK_P non-zero means clear the mask
4739 pixmap if any. COLORS_P non-zero means free colors allocated for
4740 the image, if any. */
4743 x_clear_image_1 (f
, img
, pixmap_p
, mask_p
, colors_p
)
4746 int pixmap_p
, mask_p
, colors_p
;
4748 if (pixmap_p
&& img
->pixmap
)
4750 XFreePixmap (FRAME_X_DISPLAY (f
), img
->pixmap
);
4752 img
->background_valid
= 0;
4755 if (mask_p
&& img
->mask
)
4757 XFreePixmap (FRAME_X_DISPLAY (f
), img
->mask
);
4759 img
->background_transparent_valid
= 0;
4762 if (colors_p
&& img
->ncolors
)
4764 x_free_colors (f
, img
->colors
, img
->ncolors
);
4765 xfree (img
->colors
);
4771 /* Free X resources of image IMG which is used on frame F. */
4774 x_clear_image (f
, img
)
4779 x_clear_image_1 (f
, img
, 1, 1, 1);
4784 /* Allocate color COLOR_NAME for image IMG on frame F. If color
4785 cannot be allocated, use DFLT. Add a newly allocated color to
4786 IMG->colors, so that it can be freed again. Value is the pixel
4789 static unsigned long
4790 x_alloc_image_color (f
, img
, color_name
, dflt
)
4793 Lisp_Object color_name
;
4797 unsigned long result
;
4799 xassert (STRINGP (color_name
));
4801 if (x_defined_color (f
, SDATA (color_name
), &color
, 1))
4803 /* This isn't called frequently so we get away with simply
4804 reallocating the color vector to the needed size, here. */
4807 (unsigned long *) xrealloc (img
->colors
,
4808 img
->ncolors
* sizeof *img
->colors
);
4809 img
->colors
[img
->ncolors
- 1] = color
.pixel
;
4810 result
= color
.pixel
;
4820 /***********************************************************************
4822 ***********************************************************************/
4824 static void cache_image
P_ ((struct frame
*f
, struct image
*img
));
4825 static void postprocess_image
P_ ((struct frame
*, struct image
*));
4828 /* Return a new, initialized image cache that is allocated from the
4829 heap. Call free_image_cache to free an image cache. */
4831 struct image_cache
*
4834 struct image_cache
*c
= (struct image_cache
*) xmalloc (sizeof *c
);
4837 bzero (c
, sizeof *c
);
4839 c
->images
= (struct image
**) xmalloc (c
->size
* sizeof *c
->images
);
4840 size
= IMAGE_CACHE_BUCKETS_SIZE
* sizeof *c
->buckets
;
4841 c
->buckets
= (struct image
**) xmalloc (size
);
4842 bzero (c
->buckets
, size
);
4847 /* Free image cache of frame F. Be aware that X frames share images
4851 free_image_cache (f
)
4854 struct image_cache
*c
= FRAME_X_IMAGE_CACHE (f
);
4859 /* Cache should not be referenced by any frame when freed. */
4860 xassert (c
->refcount
== 0);
4862 for (i
= 0; i
< c
->used
; ++i
)
4863 free_image (f
, c
->images
[i
]);
4867 FRAME_X_IMAGE_CACHE (f
) = NULL
;
4872 /* Clear image cache of frame F. FORCE_P non-zero means free all
4873 images. FORCE_P zero means clear only images that haven't been
4874 displayed for some time. Should be called from time to time to
4875 reduce the number of loaded images. If image-eviction-seconds is
4876 non-nil, this frees images in the cache which weren't displayed for
4877 at least that many seconds. */
4880 clear_image_cache (f
, force_p
)
4884 struct image_cache
*c
= FRAME_X_IMAGE_CACHE (f
);
4886 if (c
&& INTEGERP (Vimage_cache_eviction_delay
))
4893 old
= EMACS_SECS (t
) - XFASTINT (Vimage_cache_eviction_delay
);
4895 /* Block input so that we won't be interrupted by a SIGIO
4896 while being in an inconsistent state. */
4899 for (i
= nfreed
= 0; i
< c
->used
; ++i
)
4901 struct image
*img
= c
->images
[i
];
4903 && (force_p
|| img
->timestamp
< old
))
4905 free_image (f
, img
);
4910 /* We may be clearing the image cache because, for example,
4911 Emacs was iconified for a longer period of time. In that
4912 case, current matrices may still contain references to
4913 images freed above. So, clear these matrices. */
4916 Lisp_Object tail
, frame
;
4918 FOR_EACH_FRAME (tail
, frame
)
4920 struct frame
*f
= XFRAME (frame
);
4922 && FRAME_X_IMAGE_CACHE (f
) == c
)
4923 clear_current_matrices (f
);
4926 ++windows_or_buffers_changed
;
4934 DEFUN ("clear-image-cache", Fclear_image_cache
, Sclear_image_cache
,
4936 doc
: /* Clear the image cache of FRAME.
4937 FRAME nil or omitted means use the selected frame.
4938 FRAME t means clear the image caches of all frames. */)
4946 FOR_EACH_FRAME (tail
, frame
)
4947 if (FRAME_X_P (XFRAME (frame
)))
4948 clear_image_cache (XFRAME (frame
), 1);
4951 clear_image_cache (check_x_frame (frame
), 1);
4957 /* Compute masks and transform image IMG on frame F, as specified
4958 by the image's specification, */
4961 postprocess_image (f
, img
)
4965 /* Manipulation of the image's mask. */
4968 Lisp_Object conversion
, spec
;
4973 /* `:heuristic-mask t'
4975 means build a mask heuristically.
4976 `:heuristic-mask (R G B)'
4977 `:mask (heuristic (R G B))'
4978 means build a mask from color (R G B) in the
4981 means remove a mask, if any. */
4983 mask
= image_spec_value (spec
, QCheuristic_mask
, NULL
);
4985 x_build_heuristic_mask (f
, img
, mask
);
4990 mask
= image_spec_value (spec
, QCmask
, &found_p
);
4992 if (EQ (mask
, Qheuristic
))
4993 x_build_heuristic_mask (f
, img
, Qt
);
4994 else if (CONSP (mask
)
4995 && EQ (XCAR (mask
), Qheuristic
))
4997 if (CONSP (XCDR (mask
)))
4998 x_build_heuristic_mask (f
, img
, XCAR (XCDR (mask
)));
5000 x_build_heuristic_mask (f
, img
, XCDR (mask
));
5002 else if (NILP (mask
) && found_p
&& img
->mask
)
5004 XFreePixmap (FRAME_X_DISPLAY (f
), img
->mask
);
5010 /* Should we apply an image transformation algorithm? */
5011 conversion
= image_spec_value (spec
, QCconversion
, NULL
);
5012 if (EQ (conversion
, Qdisabled
))
5013 x_disable_image (f
, img
);
5014 else if (EQ (conversion
, Qlaplace
))
5016 else if (EQ (conversion
, Qemboss
))
5018 else if (CONSP (conversion
)
5019 && EQ (XCAR (conversion
), Qedge_detection
))
5022 tem
= XCDR (conversion
);
5024 x_edge_detection (f
, img
,
5025 Fplist_get (tem
, QCmatrix
),
5026 Fplist_get (tem
, QCcolor_adjustment
));
5032 /* Return the id of image with Lisp specification SPEC on frame F.
5033 SPEC must be a valid Lisp image specification (see valid_image_p). */
5036 lookup_image (f
, spec
)
5040 struct image_cache
*c
= FRAME_X_IMAGE_CACHE (f
);
5044 struct gcpro gcpro1
;
5047 /* F must be a window-system frame, and SPEC must be a valid image
5049 xassert (FRAME_WINDOW_P (f
));
5050 xassert (valid_image_p (spec
));
5054 /* Look up SPEC in the hash table of the image cache. */
5055 hash
= sxhash (spec
, 0);
5056 i
= hash
% IMAGE_CACHE_BUCKETS_SIZE
;
5058 for (img
= c
->buckets
[i
]; img
; img
= img
->next
)
5059 if (img
->hash
== hash
&& !NILP (Fequal (img
->spec
, spec
)))
5062 /* If not found, create a new image and cache it. */
5065 extern Lisp_Object Qpostscript
;
5068 img
= make_image (spec
, hash
);
5069 cache_image (f
, img
);
5070 img
->load_failed_p
= img
->type
->load (f
, img
) == 0;
5072 /* If we can't load the image, and we don't have a width and
5073 height, use some arbitrary width and height so that we can
5074 draw a rectangle for it. */
5075 if (img
->load_failed_p
)
5079 value
= image_spec_value (spec
, QCwidth
, NULL
);
5080 img
->width
= (INTEGERP (value
)
5081 ? XFASTINT (value
) : DEFAULT_IMAGE_WIDTH
);
5082 value
= image_spec_value (spec
, QCheight
, NULL
);
5083 img
->height
= (INTEGERP (value
)
5084 ? XFASTINT (value
) : DEFAULT_IMAGE_HEIGHT
);
5088 /* Handle image type independent image attributes
5089 `:ascent ASCENT', `:margin MARGIN', `:relief RELIEF',
5090 `:background COLOR'. */
5091 Lisp_Object ascent
, margin
, relief
, bg
;
5093 ascent
= image_spec_value (spec
, QCascent
, NULL
);
5094 if (INTEGERP (ascent
))
5095 img
->ascent
= XFASTINT (ascent
);
5096 else if (EQ (ascent
, Qcenter
))
5097 img
->ascent
= CENTERED_IMAGE_ASCENT
;
5099 margin
= image_spec_value (spec
, QCmargin
, NULL
);
5100 if (INTEGERP (margin
) && XINT (margin
) >= 0)
5101 img
->vmargin
= img
->hmargin
= XFASTINT (margin
);
5102 else if (CONSP (margin
) && INTEGERP (XCAR (margin
))
5103 && INTEGERP (XCDR (margin
)))
5105 if (XINT (XCAR (margin
)) > 0)
5106 img
->hmargin
= XFASTINT (XCAR (margin
));
5107 if (XINT (XCDR (margin
)) > 0)
5108 img
->vmargin
= XFASTINT (XCDR (margin
));
5111 relief
= image_spec_value (spec
, QCrelief
, NULL
);
5112 if (INTEGERP (relief
))
5114 img
->relief
= XINT (relief
);
5115 img
->hmargin
+= abs (img
->relief
);
5116 img
->vmargin
+= abs (img
->relief
);
5119 if (! img
->background_valid
)
5121 bg
= image_spec_value (img
->spec
, QCbackground
, NULL
);
5125 = x_alloc_image_color (f
, img
, bg
,
5126 FRAME_BACKGROUND_PIXEL (f
));
5127 img
->background_valid
= 1;
5131 /* Do image transformations and compute masks, unless we
5132 don't have the image yet. */
5133 if (!EQ (*img
->type
->type
, Qpostscript
))
5134 postprocess_image (f
, img
);
5138 xassert (!interrupt_input_blocked
);
5141 /* We're using IMG, so set its timestamp to `now'. */
5142 EMACS_GET_TIME (now
);
5143 img
->timestamp
= EMACS_SECS (now
);
5147 /* Value is the image id. */
5152 /* Cache image IMG in the image cache of frame F. */
5155 cache_image (f
, img
)
5159 struct image_cache
*c
= FRAME_X_IMAGE_CACHE (f
);
5162 /* Find a free slot in c->images. */
5163 for (i
= 0; i
< c
->used
; ++i
)
5164 if (c
->images
[i
] == NULL
)
5167 /* If no free slot found, maybe enlarge c->images. */
5168 if (i
== c
->used
&& c
->used
== c
->size
)
5171 c
->images
= (struct image
**) xrealloc (c
->images
,
5172 c
->size
* sizeof *c
->images
);
5175 /* Add IMG to c->images, and assign IMG an id. */
5181 /* Add IMG to the cache's hash table. */
5182 i
= img
->hash
% IMAGE_CACHE_BUCKETS_SIZE
;
5183 img
->next
= c
->buckets
[i
];
5185 img
->next
->prev
= img
;
5187 c
->buckets
[i
] = img
;
5191 /* Call FN on every image in the image cache of frame F. Used to mark
5192 Lisp Objects in the image cache. */
5195 forall_images_in_image_cache (f
, fn
)
5197 void (*fn
) P_ ((struct image
*img
));
5199 if (FRAME_LIVE_P (f
) && FRAME_X_P (f
))
5201 struct image_cache
*c
= FRAME_X_IMAGE_CACHE (f
);
5205 for (i
= 0; i
< c
->used
; ++i
)
5214 /***********************************************************************
5216 ***********************************************************************/
5218 static int x_create_x_image_and_pixmap
P_ ((struct frame
*, int, int, int,
5219 XImage
**, Pixmap
*));
5220 static void x_destroy_x_image
P_ ((XImage
*));
5221 static void x_put_x_image
P_ ((struct frame
*, XImage
*, Pixmap
, int, int));
5224 /* Create an XImage and a pixmap of size WIDTH x HEIGHT for use on
5225 frame F. Set *XIMG and *PIXMAP to the XImage and Pixmap created.
5226 Set (*XIMG)->data to a raster of WIDTH x HEIGHT pixels allocated
5227 via xmalloc. Print error messages via image_error if an error
5228 occurs. Value is non-zero if successful. */
5231 x_create_x_image_and_pixmap (f
, width
, height
, depth
, ximg
, pixmap
)
5233 int width
, height
, depth
;
5237 Display
*display
= FRAME_X_DISPLAY (f
);
5238 Screen
*screen
= FRAME_X_SCREEN (f
);
5239 Window window
= FRAME_X_WINDOW (f
);
5241 xassert (interrupt_input_blocked
);
5244 depth
= DefaultDepthOfScreen (screen
);
5245 *ximg
= XCreateImage (display
, DefaultVisualOfScreen (screen
),
5246 depth
, ZPixmap
, 0, NULL
, width
, height
,
5247 depth
> 16 ? 32 : depth
> 8 ? 16 : 8, 0);
5250 image_error ("Unable to allocate X image", Qnil
, Qnil
);
5254 /* Allocate image raster. */
5255 (*ximg
)->data
= (char *) xmalloc ((*ximg
)->bytes_per_line
* height
);
5257 /* Allocate a pixmap of the same size. */
5258 *pixmap
= XCreatePixmap (display
, window
, width
, height
, depth
);
5259 if (*pixmap
== None
)
5261 x_destroy_x_image (*ximg
);
5263 image_error ("Unable to create X pixmap", Qnil
, Qnil
);
5271 /* Destroy XImage XIMG. Free XIMG->data. */
5274 x_destroy_x_image (ximg
)
5277 xassert (interrupt_input_blocked
);
5282 XDestroyImage (ximg
);
5287 /* Put XImage XIMG into pixmap PIXMAP on frame F. WIDTH and HEIGHT
5288 are width and height of both the image and pixmap. */
5291 x_put_x_image (f
, ximg
, pixmap
, width
, height
)
5299 xassert (interrupt_input_blocked
);
5300 gc
= XCreateGC (FRAME_X_DISPLAY (f
), pixmap
, 0, NULL
);
5301 XPutImage (FRAME_X_DISPLAY (f
), pixmap
, gc
, ximg
, 0, 0, 0, 0, width
, height
);
5302 XFreeGC (FRAME_X_DISPLAY (f
), gc
);
5307 /***********************************************************************
5309 ***********************************************************************/
5311 static Lisp_Object x_find_image_file
P_ ((Lisp_Object
));
5312 static char *slurp_file
P_ ((char *, int *));
5315 /* Find image file FILE. Look in data-directory, then
5316 x-bitmap-file-path. Value is the full name of the file found, or
5317 nil if not found. */
5320 x_find_image_file (file
)
5323 Lisp_Object file_found
, search_path
;
5324 struct gcpro gcpro1
, gcpro2
;
5328 search_path
= Fcons (Vdata_directory
, Vx_bitmap_file_path
);
5329 GCPRO2 (file_found
, search_path
);
5331 /* Try to find FILE in data-directory, then x-bitmap-file-path. */
5332 fd
= openp (search_path
, file
, Qnil
, &file_found
, Qnil
);
5344 /* Read FILE into memory. Value is a pointer to a buffer allocated
5345 with xmalloc holding FILE's contents. Value is null if an error
5346 occurred. *SIZE is set to the size of the file. */
5349 slurp_file (file
, size
)
5357 if (stat (file
, &st
) == 0
5358 && (fp
= fopen (file
, "r")) != NULL
5359 && (buf
= (char *) xmalloc (st
.st_size
),
5360 fread (buf
, 1, st
.st_size
, fp
) == st
.st_size
))
5381 /***********************************************************************
5383 ***********************************************************************/
5385 static int xbm_scan
P_ ((char **, char *, char *, int *));
5386 static int xbm_load
P_ ((struct frame
*f
, struct image
*img
));
5387 static int xbm_load_image
P_ ((struct frame
*f
, struct image
*img
,
5389 static int xbm_image_p
P_ ((Lisp_Object object
));
5390 static int xbm_read_bitmap_data
P_ ((char *, char *, int *, int *,
5392 static int xbm_file_p
P_ ((Lisp_Object
));
5395 /* Indices of image specification fields in xbm_format, below. */
5397 enum xbm_keyword_index
5415 /* Vector of image_keyword structures describing the format
5416 of valid XBM image specifications. */
5418 static struct image_keyword xbm_format
[XBM_LAST
] =
5420 {":type", IMAGE_SYMBOL_VALUE
, 1},
5421 {":file", IMAGE_STRING_VALUE
, 0},
5422 {":width", IMAGE_POSITIVE_INTEGER_VALUE
, 0},
5423 {":height", IMAGE_POSITIVE_INTEGER_VALUE
, 0},
5424 {":data", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
5425 {":foreground", IMAGE_STRING_OR_NIL_VALUE
, 0},
5426 {":background", IMAGE_STRING_OR_NIL_VALUE
, 0},
5427 {":ascent", IMAGE_ASCENT_VALUE
, 0},
5428 {":margin", IMAGE_POSITIVE_INTEGER_VALUE_OR_PAIR
, 0},
5429 {":relief", IMAGE_INTEGER_VALUE
, 0},
5430 {":conversion", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
5431 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
5432 {":mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0}
5435 /* Structure describing the image type XBM. */
5437 static struct image_type xbm_type
=
5446 /* Tokens returned from xbm_scan. */
5455 /* Return non-zero if OBJECT is a valid XBM-type image specification.
5456 A valid specification is a list starting with the symbol `image'
5457 The rest of the list is a property list which must contain an
5460 If the specification specifies a file to load, it must contain
5461 an entry `:file FILENAME' where FILENAME is a string.
5463 If the specification is for a bitmap loaded from memory it must
5464 contain `:width WIDTH', `:height HEIGHT', and `:data DATA', where
5465 WIDTH and HEIGHT are integers > 0. DATA may be:
5467 1. a string large enough to hold the bitmap data, i.e. it must
5468 have a size >= (WIDTH + 7) / 8 * HEIGHT
5470 2. a bool-vector of size >= WIDTH * HEIGHT
5472 3. a vector of strings or bool-vectors, one for each line of the
5475 4. A string containing an in-memory XBM file. WIDTH and HEIGHT
5476 may not be specified in this case because they are defined in the
5479 Both the file and data forms may contain the additional entries
5480 `:background COLOR' and `:foreground COLOR'. If not present,
5481 foreground and background of the frame on which the image is
5482 displayed is used. */
5485 xbm_image_p (object
)
5488 struct image_keyword kw
[XBM_LAST
];
5490 bcopy (xbm_format
, kw
, sizeof kw
);
5491 if (!parse_image_spec (object
, kw
, XBM_LAST
, Qxbm
))
5494 xassert (EQ (kw
[XBM_TYPE
].value
, Qxbm
));
5496 if (kw
[XBM_FILE
].count
)
5498 if (kw
[XBM_WIDTH
].count
|| kw
[XBM_HEIGHT
].count
|| kw
[XBM_DATA
].count
)
5501 else if (kw
[XBM_DATA
].count
&& xbm_file_p (kw
[XBM_DATA
].value
))
5503 /* In-memory XBM file. */
5504 if (kw
[XBM_WIDTH
].count
|| kw
[XBM_HEIGHT
].count
|| kw
[XBM_FILE
].count
)
5512 /* Entries for `:width', `:height' and `:data' must be present. */
5513 if (!kw
[XBM_WIDTH
].count
5514 || !kw
[XBM_HEIGHT
].count
5515 || !kw
[XBM_DATA
].count
)
5518 data
= kw
[XBM_DATA
].value
;
5519 width
= XFASTINT (kw
[XBM_WIDTH
].value
);
5520 height
= XFASTINT (kw
[XBM_HEIGHT
].value
);
5522 /* Check type of data, and width and height against contents of
5528 /* Number of elements of the vector must be >= height. */
5529 if (XVECTOR (data
)->size
< height
)
5532 /* Each string or bool-vector in data must be large enough
5533 for one line of the image. */
5534 for (i
= 0; i
< height
; ++i
)
5536 Lisp_Object elt
= XVECTOR (data
)->contents
[i
];
5541 < (width
+ BITS_PER_CHAR
- 1) / BITS_PER_CHAR
)
5544 else if (BOOL_VECTOR_P (elt
))
5546 if (XBOOL_VECTOR (elt
)->size
< width
)
5553 else if (STRINGP (data
))
5556 < (width
+ BITS_PER_CHAR
- 1) / BITS_PER_CHAR
* height
)
5559 else if (BOOL_VECTOR_P (data
))
5561 if (XBOOL_VECTOR (data
)->size
< width
* height
)
5572 /* Scan a bitmap file. FP is the stream to read from. Value is
5573 either an enumerator from enum xbm_token, or a character for a
5574 single-character token, or 0 at end of file. If scanning an
5575 identifier, store the lexeme of the identifier in SVAL. If
5576 scanning a number, store its value in *IVAL. */
5579 xbm_scan (s
, end
, sval
, ival
)
5588 /* Skip white space. */
5589 while (*s
< end
&& (c
= *(*s
)++, isspace (c
)))
5594 else if (isdigit (c
))
5596 int value
= 0, digit
;
5598 if (c
== '0' && *s
< end
)
5601 if (c
== 'x' || c
== 'X')
5608 else if (c
>= 'a' && c
<= 'f')
5609 digit
= c
- 'a' + 10;
5610 else if (c
>= 'A' && c
<= 'F')
5611 digit
= c
- 'A' + 10;
5614 value
= 16 * value
+ digit
;
5617 else if (isdigit (c
))
5621 && (c
= *(*s
)++, isdigit (c
)))
5622 value
= 8 * value
+ c
- '0';
5629 && (c
= *(*s
)++, isdigit (c
)))
5630 value
= 10 * value
+ c
- '0';
5638 else if (isalpha (c
) || c
== '_')
5642 && (c
= *(*s
)++, (isalnum (c
) || c
== '_')))
5649 else if (c
== '/' && **s
== '*')
5651 /* C-style comment. */
5653 while (**s
&& (**s
!= '*' || *(*s
+ 1) != '/'))
5666 /* Replacement for XReadBitmapFileData which isn't available under old
5667 X versions. CONTENTS is a pointer to a buffer to parse; END is the
5668 buffer's end. Set *WIDTH and *HEIGHT to the width and height of
5669 the image. Return in *DATA the bitmap data allocated with xmalloc.
5670 Value is non-zero if successful. DATA null means just test if
5671 CONTENTS looks like an in-memory XBM file. */
5674 xbm_read_bitmap_data (contents
, end
, width
, height
, data
)
5675 char *contents
, *end
;
5676 int *width
, *height
;
5677 unsigned char **data
;
5680 char buffer
[BUFSIZ
];
5683 int bytes_per_line
, i
, nbytes
;
5689 LA1 = xbm_scan (&s, end, buffer, &value)
5691 #define expect(TOKEN) \
5692 if (LA1 != (TOKEN)) \
5697 #define expect_ident(IDENT) \
5698 if (LA1 == XBM_TK_IDENT && strcmp (buffer, (IDENT)) == 0) \
5703 *width
= *height
= -1;
5706 LA1
= xbm_scan (&s
, end
, buffer
, &value
);
5708 /* Parse defines for width, height and hot-spots. */
5712 expect_ident ("define");
5713 expect (XBM_TK_IDENT
);
5715 if (LA1
== XBM_TK_NUMBER
);
5717 char *p
= strrchr (buffer
, '_');
5718 p
= p
? p
+ 1 : buffer
;
5719 if (strcmp (p
, "width") == 0)
5721 else if (strcmp (p
, "height") == 0)
5724 expect (XBM_TK_NUMBER
);
5727 if (*width
< 0 || *height
< 0)
5729 else if (data
== NULL
)
5732 /* Parse bits. Must start with `static'. */
5733 expect_ident ("static");
5734 if (LA1
== XBM_TK_IDENT
)
5736 if (strcmp (buffer
, "unsigned") == 0)
5739 expect_ident ("char");
5741 else if (strcmp (buffer
, "short") == 0)
5745 if (*width
% 16 && *width
% 16 < 9)
5748 else if (strcmp (buffer
, "char") == 0)
5756 expect (XBM_TK_IDENT
);
5762 bytes_per_line
= (*width
+ 7) / 8 + padding_p
;
5763 nbytes
= bytes_per_line
* *height
;
5764 p
= *data
= (char *) xmalloc (nbytes
);
5768 for (i
= 0; i
< nbytes
; i
+= 2)
5771 expect (XBM_TK_NUMBER
);
5774 if (!padding_p
|| ((i
+ 2) % bytes_per_line
))
5777 if (LA1
== ',' || LA1
== '}')
5785 for (i
= 0; i
< nbytes
; ++i
)
5788 expect (XBM_TK_NUMBER
);
5792 if (LA1
== ',' || LA1
== '}')
5817 /* Load XBM image IMG which will be displayed on frame F from buffer
5818 CONTENTS. END is the end of the buffer. Value is non-zero if
5822 xbm_load_image (f
, img
, contents
, end
)
5825 char *contents
, *end
;
5828 unsigned char *data
;
5831 rc
= xbm_read_bitmap_data (contents
, end
, &img
->width
, &img
->height
, &data
);
5834 int depth
= DefaultDepthOfScreen (FRAME_X_SCREEN (f
));
5835 unsigned long foreground
= FRAME_FOREGROUND_PIXEL (f
);
5836 unsigned long background
= FRAME_BACKGROUND_PIXEL (f
);
5839 xassert (img
->width
> 0 && img
->height
> 0);
5841 /* Get foreground and background colors, maybe allocate colors. */
5842 value
= image_spec_value (img
->spec
, QCforeground
, NULL
);
5844 foreground
= x_alloc_image_color (f
, img
, value
, foreground
);
5845 value
= image_spec_value (img
->spec
, QCbackground
, NULL
);
5848 background
= x_alloc_image_color (f
, img
, value
, background
);
5849 img
->background
= background
;
5850 img
->background_valid
= 1;
5854 = XCreatePixmapFromBitmapData (FRAME_X_DISPLAY (f
),
5857 img
->width
, img
->height
,
5858 foreground
, background
,
5862 if (img
->pixmap
== None
)
5864 x_clear_image (f
, img
);
5865 image_error ("Unable to create X pixmap for `%s'", img
->spec
, Qnil
);
5871 image_error ("Error loading XBM image `%s'", img
->spec
, Qnil
);
5877 /* Value is non-zero if DATA looks like an in-memory XBM file. */
5884 return (STRINGP (data
)
5885 && xbm_read_bitmap_data (SDATA (data
),
5892 /* Fill image IMG which is used on frame F with pixmap data. Value is
5893 non-zero if successful. */
5901 Lisp_Object file_name
;
5903 xassert (xbm_image_p (img
->spec
));
5905 /* If IMG->spec specifies a file name, create a non-file spec from it. */
5906 file_name
= image_spec_value (img
->spec
, QCfile
, NULL
);
5907 if (STRINGP (file_name
))
5912 struct gcpro gcpro1
;
5914 file
= x_find_image_file (file_name
);
5916 if (!STRINGP (file
))
5918 image_error ("Cannot find image file `%s'", file_name
, Qnil
);
5923 contents
= slurp_file (SDATA (file
), &size
);
5924 if (contents
== NULL
)
5926 image_error ("Error loading XBM image `%s'", img
->spec
, Qnil
);
5931 success_p
= xbm_load_image (f
, img
, contents
, contents
+ size
);
5936 struct image_keyword fmt
[XBM_LAST
];
5939 unsigned long foreground
= FRAME_FOREGROUND_PIXEL (f
);
5940 unsigned long background
= FRAME_BACKGROUND_PIXEL (f
);
5943 int in_memory_file_p
= 0;
5945 /* See if data looks like an in-memory XBM file. */
5946 data
= image_spec_value (img
->spec
, QCdata
, NULL
);
5947 in_memory_file_p
= xbm_file_p (data
);
5949 /* Parse the image specification. */
5950 bcopy (xbm_format
, fmt
, sizeof fmt
);
5951 parsed_p
= parse_image_spec (img
->spec
, fmt
, XBM_LAST
, Qxbm
);
5954 /* Get specified width, and height. */
5955 if (!in_memory_file_p
)
5957 img
->width
= XFASTINT (fmt
[XBM_WIDTH
].value
);
5958 img
->height
= XFASTINT (fmt
[XBM_HEIGHT
].value
);
5959 xassert (img
->width
> 0 && img
->height
> 0);
5962 /* Get foreground and background colors, maybe allocate colors. */
5963 if (fmt
[XBM_FOREGROUND
].count
5964 && STRINGP (fmt
[XBM_FOREGROUND
].value
))
5965 foreground
= x_alloc_image_color (f
, img
, fmt
[XBM_FOREGROUND
].value
,
5967 if (fmt
[XBM_BACKGROUND
].count
5968 && STRINGP (fmt
[XBM_BACKGROUND
].value
))
5969 background
= x_alloc_image_color (f
, img
, fmt
[XBM_BACKGROUND
].value
,
5972 if (in_memory_file_p
)
5973 success_p
= xbm_load_image (f
, img
, SDATA (data
),
5982 int nbytes
= (img
->width
+ BITS_PER_CHAR
- 1) / BITS_PER_CHAR
;
5984 p
= bits
= (char *) alloca (nbytes
* img
->height
);
5985 for (i
= 0; i
< img
->height
; ++i
, p
+= nbytes
)
5987 Lisp_Object line
= XVECTOR (data
)->contents
[i
];
5989 bcopy (SDATA (line
), p
, nbytes
);
5991 bcopy (XBOOL_VECTOR (line
)->data
, p
, nbytes
);
5994 else if (STRINGP (data
))
5995 bits
= SDATA (data
);
5997 bits
= XBOOL_VECTOR (data
)->data
;
5999 /* Create the pixmap. */
6000 depth
= DefaultDepthOfScreen (FRAME_X_SCREEN (f
));
6002 = XCreatePixmapFromBitmapData (FRAME_X_DISPLAY (f
),
6005 img
->width
, img
->height
,
6006 foreground
, background
,
6012 image_error ("Unable to create pixmap for XBM image `%s'",
6014 x_clear_image (f
, img
);
6024 /***********************************************************************
6026 ***********************************************************************/
6030 static int xpm_image_p
P_ ((Lisp_Object object
));
6031 static int xpm_load
P_ ((struct frame
*f
, struct image
*img
));
6032 static int xpm_valid_color_symbols_p
P_ ((Lisp_Object
));
6034 #include "X11/xpm.h"
6036 /* The symbol `xpm' identifying XPM-format images. */
6040 /* Indices of image specification fields in xpm_format, below. */
6042 enum xpm_keyword_index
6058 /* Vector of image_keyword structures describing the format
6059 of valid XPM image specifications. */
6061 static struct image_keyword xpm_format
[XPM_LAST
] =
6063 {":type", IMAGE_SYMBOL_VALUE
, 1},
6064 {":file", IMAGE_STRING_VALUE
, 0},
6065 {":data", IMAGE_STRING_VALUE
, 0},
6066 {":ascent", IMAGE_ASCENT_VALUE
, 0},
6067 {":margin", IMAGE_POSITIVE_INTEGER_VALUE_OR_PAIR
, 0},
6068 {":relief", IMAGE_INTEGER_VALUE
, 0},
6069 {":conversion", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
6070 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
6071 {":mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
6072 {":color-symbols", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
6073 {":background", IMAGE_STRING_OR_NIL_VALUE
, 0}
6076 /* Structure describing the image type XBM. */
6078 static struct image_type xpm_type
=
6088 /* Define ALLOC_XPM_COLORS if we can use Emacs' own color allocation
6089 functions for allocating image colors. Our own functions handle
6090 color allocation failures more gracefully than the ones on the XPM
6093 #if defined XpmAllocColor && defined XpmFreeColors && defined XpmColorClosure
6094 #define ALLOC_XPM_COLORS
6097 #ifdef ALLOC_XPM_COLORS
6099 static void xpm_init_color_cache
P_ ((struct frame
*, XpmAttributes
*));
6100 static void xpm_free_color_cache
P_ ((void));
6101 static int xpm_lookup_color
P_ ((struct frame
*, char *, XColor
*));
6102 static int xpm_color_bucket
P_ ((char *));
6103 static struct xpm_cached_color
*xpm_cache_color
P_ ((struct frame
*, char *,
6106 /* An entry in a hash table used to cache color definitions of named
6107 colors. This cache is necessary to speed up XPM image loading in
6108 case we do color allocations ourselves. Without it, we would need
6109 a call to XParseColor per pixel in the image. */
6111 struct xpm_cached_color
6113 /* Next in collision chain. */
6114 struct xpm_cached_color
*next
;
6116 /* Color definition (RGB and pixel color). */
6123 /* The hash table used for the color cache, and its bucket vector
6126 #define XPM_COLOR_CACHE_BUCKETS 1001
6127 struct xpm_cached_color
**xpm_color_cache
;
6129 /* Initialize the color cache. */
6132 xpm_init_color_cache (f
, attrs
)
6134 XpmAttributes
*attrs
;
6136 size_t nbytes
= XPM_COLOR_CACHE_BUCKETS
* sizeof *xpm_color_cache
;
6137 xpm_color_cache
= (struct xpm_cached_color
**) xmalloc (nbytes
);
6138 memset (xpm_color_cache
, 0, nbytes
);
6139 init_color_table ();
6141 if (attrs
->valuemask
& XpmColorSymbols
)
6146 for (i
= 0; i
< attrs
->numsymbols
; ++i
)
6147 if (XParseColor (FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
),
6148 attrs
->colorsymbols
[i
].value
, &color
))
6150 color
.pixel
= lookup_rgb_color (f
, color
.red
, color
.green
,
6152 xpm_cache_color (f
, attrs
->colorsymbols
[i
].name
, &color
, -1);
6158 /* Free the color cache. */
6161 xpm_free_color_cache ()
6163 struct xpm_cached_color
*p
, *next
;
6166 for (i
= 0; i
< XPM_COLOR_CACHE_BUCKETS
; ++i
)
6167 for (p
= xpm_color_cache
[i
]; p
; p
= next
)
6173 xfree (xpm_color_cache
);
6174 xpm_color_cache
= NULL
;
6175 free_color_table ();
6179 /* Return the bucket index for color named COLOR_NAME in the color
6183 xpm_color_bucket (color_name
)
6189 for (s
= color_name
; *s
; ++s
)
6191 return h
%= XPM_COLOR_CACHE_BUCKETS
;
6195 /* On frame F, cache values COLOR for color with name COLOR_NAME.
6196 BUCKET, if >= 0, is a precomputed bucket index. Value is the cache
6199 static struct xpm_cached_color
*
6200 xpm_cache_color (f
, color_name
, color
, bucket
)
6207 struct xpm_cached_color
*p
;
6210 bucket
= xpm_color_bucket (color_name
);
6212 nbytes
= sizeof *p
+ strlen (color_name
);
6213 p
= (struct xpm_cached_color
*) xmalloc (nbytes
);
6214 strcpy (p
->name
, color_name
);
6216 p
->next
= xpm_color_cache
[bucket
];
6217 xpm_color_cache
[bucket
] = p
;
6222 /* Look up color COLOR_NAME for frame F in the color cache. If found,
6223 return the cached definition in *COLOR. Otherwise, make a new
6224 entry in the cache and allocate the color. Value is zero if color
6225 allocation failed. */
6228 xpm_lookup_color (f
, color_name
, color
)
6233 struct xpm_cached_color
*p
;
6234 int h
= xpm_color_bucket (color_name
);
6236 for (p
= xpm_color_cache
[h
]; p
; p
= p
->next
)
6237 if (strcmp (p
->name
, color_name
) == 0)
6242 else if (XParseColor (FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
),
6245 color
->pixel
= lookup_rgb_color (f
, color
->red
, color
->green
,
6247 p
= xpm_cache_color (f
, color_name
, color
, h
);
6254 /* Callback for allocating color COLOR_NAME. Called from the XPM lib.
6255 CLOSURE is a pointer to the frame on which we allocate the
6256 color. Return in *COLOR the allocated color. Value is non-zero
6260 xpm_alloc_color (dpy
, cmap
, color_name
, color
, closure
)
6267 return xpm_lookup_color ((struct frame
*) closure
, color_name
, color
);
6271 /* Callback for freeing NPIXELS colors contained in PIXELS. CLOSURE
6272 is a pointer to the frame on which we allocate the color. Value is
6273 non-zero if successful. */
6276 xpm_free_colors (dpy
, cmap
, pixels
, npixels
, closure
)
6286 #endif /* ALLOC_XPM_COLORS */
6289 /* Value is non-zero if COLOR_SYMBOLS is a valid color symbols list
6290 for XPM images. Such a list must consist of conses whose car and
6294 xpm_valid_color_symbols_p (color_symbols
)
6295 Lisp_Object color_symbols
;
6297 while (CONSP (color_symbols
))
6299 Lisp_Object sym
= XCAR (color_symbols
);
6301 || !STRINGP (XCAR (sym
))
6302 || !STRINGP (XCDR (sym
)))
6304 color_symbols
= XCDR (color_symbols
);
6307 return NILP (color_symbols
);
6311 /* Value is non-zero if OBJECT is a valid XPM image specification. */
6314 xpm_image_p (object
)
6317 struct image_keyword fmt
[XPM_LAST
];
6318 bcopy (xpm_format
, fmt
, sizeof fmt
);
6319 return (parse_image_spec (object
, fmt
, XPM_LAST
, Qxpm
)
6320 /* Either `:file' or `:data' must be present. */
6321 && fmt
[XPM_FILE
].count
+ fmt
[XPM_DATA
].count
== 1
6322 /* Either no `:color-symbols' or it's a list of conses
6323 whose car and cdr are strings. */
6324 && (fmt
[XPM_COLOR_SYMBOLS
].count
== 0
6325 || xpm_valid_color_symbols_p (fmt
[XPM_COLOR_SYMBOLS
].value
)));
6329 /* Load image IMG which will be displayed on frame F. Value is
6330 non-zero if successful. */
6338 XpmAttributes attrs
;
6339 Lisp_Object specified_file
, color_symbols
;
6341 /* Configure the XPM lib. Use the visual of frame F. Allocate
6342 close colors. Return colors allocated. */
6343 bzero (&attrs
, sizeof attrs
);
6344 attrs
.visual
= FRAME_X_VISUAL (f
);
6345 attrs
.colormap
= FRAME_X_COLORMAP (f
);
6346 attrs
.valuemask
|= XpmVisual
;
6347 attrs
.valuemask
|= XpmColormap
;
6349 #ifdef ALLOC_XPM_COLORS
6350 /* Allocate colors with our own functions which handle
6351 failing color allocation more gracefully. */
6352 attrs
.color_closure
= f
;
6353 attrs
.alloc_color
= xpm_alloc_color
;
6354 attrs
.free_colors
= xpm_free_colors
;
6355 attrs
.valuemask
|= XpmAllocColor
| XpmFreeColors
| XpmColorClosure
;
6356 #else /* not ALLOC_XPM_COLORS */
6357 /* Let the XPM lib allocate colors. */
6358 attrs
.valuemask
|= XpmReturnAllocPixels
;
6359 #ifdef XpmAllocCloseColors
6360 attrs
.alloc_close_colors
= 1;
6361 attrs
.valuemask
|= XpmAllocCloseColors
;
6362 #else /* not XpmAllocCloseColors */
6363 attrs
.closeness
= 600;
6364 attrs
.valuemask
|= XpmCloseness
;
6365 #endif /* not XpmAllocCloseColors */
6366 #endif /* ALLOC_XPM_COLORS */
6368 /* If image specification contains symbolic color definitions, add
6369 these to `attrs'. */
6370 color_symbols
= image_spec_value (img
->spec
, QCcolor_symbols
, NULL
);
6371 if (CONSP (color_symbols
))
6374 XpmColorSymbol
*xpm_syms
;
6377 attrs
.valuemask
|= XpmColorSymbols
;
6379 /* Count number of symbols. */
6380 attrs
.numsymbols
= 0;
6381 for (tail
= color_symbols
; CONSP (tail
); tail
= XCDR (tail
))
6384 /* Allocate an XpmColorSymbol array. */
6385 size
= attrs
.numsymbols
* sizeof *xpm_syms
;
6386 xpm_syms
= (XpmColorSymbol
*) alloca (size
);
6387 bzero (xpm_syms
, size
);
6388 attrs
.colorsymbols
= xpm_syms
;
6390 /* Fill the color symbol array. */
6391 for (tail
= color_symbols
, i
= 0;
6393 ++i
, tail
= XCDR (tail
))
6395 Lisp_Object name
= XCAR (XCAR (tail
));
6396 Lisp_Object color
= XCDR (XCAR (tail
));
6397 xpm_syms
[i
].name
= (char *) alloca (SCHARS (name
) + 1);
6398 strcpy (xpm_syms
[i
].name
, SDATA (name
));
6399 xpm_syms
[i
].value
= (char *) alloca (SCHARS (color
) + 1);
6400 strcpy (xpm_syms
[i
].value
, SDATA (color
));
6404 /* Create a pixmap for the image, either from a file, or from a
6405 string buffer containing data in the same format as an XPM file. */
6406 #ifdef ALLOC_XPM_COLORS
6407 xpm_init_color_cache (f
, &attrs
);
6410 specified_file
= image_spec_value (img
->spec
, QCfile
, NULL
);
6411 if (STRINGP (specified_file
))
6413 Lisp_Object file
= x_find_image_file (specified_file
);
6414 if (!STRINGP (file
))
6416 image_error ("Cannot find image file `%s'", specified_file
, Qnil
);
6420 rc
= XpmReadFileToPixmap (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
6421 SDATA (file
), &img
->pixmap
, &img
->mask
,
6426 Lisp_Object buffer
= image_spec_value (img
->spec
, QCdata
, NULL
);
6427 rc
= XpmCreatePixmapFromBuffer (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
6429 &img
->pixmap
, &img
->mask
,
6433 if (rc
== XpmSuccess
)
6435 #ifdef ALLOC_XPM_COLORS
6436 img
->colors
= colors_in_color_table (&img
->ncolors
);
6437 #else /* not ALLOC_XPM_COLORS */
6440 img
->ncolors
= attrs
.nalloc_pixels
;
6441 img
->colors
= (unsigned long *) xmalloc (img
->ncolors
6442 * sizeof *img
->colors
);
6443 for (i
= 0; i
< attrs
.nalloc_pixels
; ++i
)
6445 img
->colors
[i
] = attrs
.alloc_pixels
[i
];
6446 #ifdef DEBUG_X_COLORS
6447 register_color (img
->colors
[i
]);
6450 #endif /* not ALLOC_XPM_COLORS */
6452 img
->width
= attrs
.width
;
6453 img
->height
= attrs
.height
;
6454 xassert (img
->width
> 0 && img
->height
> 0);
6456 /* The call to XpmFreeAttributes below frees attrs.alloc_pixels. */
6457 XpmFreeAttributes (&attrs
);
6464 image_error ("Error opening XPM file (%s)", img
->spec
, Qnil
);
6467 case XpmFileInvalid
:
6468 image_error ("Invalid XPM file (%s)", img
->spec
, Qnil
);
6472 image_error ("Out of memory (%s)", img
->spec
, Qnil
);
6475 case XpmColorFailed
:
6476 image_error ("Color allocation error (%s)", img
->spec
, Qnil
);
6480 image_error ("Unknown error (%s)", img
->spec
, Qnil
);
6485 #ifdef ALLOC_XPM_COLORS
6486 xpm_free_color_cache ();
6488 return rc
== XpmSuccess
;
6491 #endif /* HAVE_XPM != 0 */
6494 /***********************************************************************
6496 ***********************************************************************/
6498 /* An entry in the color table mapping an RGB color to a pixel color. */
6503 unsigned long pixel
;
6505 /* Next in color table collision list. */
6506 struct ct_color
*next
;
6509 /* The bucket vector size to use. Must be prime. */
6513 /* Value is a hash of the RGB color given by R, G, and B. */
6515 #define CT_HASH_RGB(R, G, B) (((R) << 16) ^ ((G) << 8) ^ (B))
6517 /* The color hash table. */
6519 struct ct_color
**ct_table
;
6521 /* Number of entries in the color table. */
6523 int ct_colors_allocated
;
6525 /* Initialize the color table. */
6530 int size
= CT_SIZE
* sizeof (*ct_table
);
6531 ct_table
= (struct ct_color
**) xmalloc (size
);
6532 bzero (ct_table
, size
);
6533 ct_colors_allocated
= 0;
6537 /* Free memory associated with the color table. */
6543 struct ct_color
*p
, *next
;
6545 for (i
= 0; i
< CT_SIZE
; ++i
)
6546 for (p
= ct_table
[i
]; p
; p
= next
)
6557 /* Value is a pixel color for RGB color R, G, B on frame F. If an
6558 entry for that color already is in the color table, return the
6559 pixel color of that entry. Otherwise, allocate a new color for R,
6560 G, B, and make an entry in the color table. */
6562 static unsigned long
6563 lookup_rgb_color (f
, r
, g
, b
)
6567 unsigned hash
= CT_HASH_RGB (r
, g
, b
);
6568 int i
= hash
% CT_SIZE
;
6571 for (p
= ct_table
[i
]; p
; p
= p
->next
)
6572 if (p
->r
== r
&& p
->g
== g
&& p
->b
== b
)
6585 cmap
= FRAME_X_COLORMAP (f
);
6586 rc
= x_alloc_nearest_color (f
, cmap
, &color
);
6590 ++ct_colors_allocated
;
6592 p
= (struct ct_color
*) xmalloc (sizeof *p
);
6596 p
->pixel
= color
.pixel
;
6597 p
->next
= ct_table
[i
];
6601 return FRAME_FOREGROUND_PIXEL (f
);
6608 /* Look up pixel color PIXEL which is used on frame F in the color
6609 table. If not already present, allocate it. Value is PIXEL. */
6611 static unsigned long
6612 lookup_pixel_color (f
, pixel
)
6614 unsigned long pixel
;
6616 int i
= pixel
% CT_SIZE
;
6619 for (p
= ct_table
[i
]; p
; p
= p
->next
)
6620 if (p
->pixel
== pixel
)
6629 cmap
= FRAME_X_COLORMAP (f
);
6630 color
.pixel
= pixel
;
6631 x_query_color (f
, &color
);
6632 rc
= x_alloc_nearest_color (f
, cmap
, &color
);
6636 ++ct_colors_allocated
;
6638 p
= (struct ct_color
*) xmalloc (sizeof *p
);
6643 p
->next
= ct_table
[i
];
6647 return FRAME_FOREGROUND_PIXEL (f
);
6654 /* Value is a vector of all pixel colors contained in the color table,
6655 allocated via xmalloc. Set *N to the number of colors. */
6657 static unsigned long *
6658 colors_in_color_table (n
)
6663 unsigned long *colors
;
6665 if (ct_colors_allocated
== 0)
6672 colors
= (unsigned long *) xmalloc (ct_colors_allocated
6674 *n
= ct_colors_allocated
;
6676 for (i
= j
= 0; i
< CT_SIZE
; ++i
)
6677 for (p
= ct_table
[i
]; p
; p
= p
->next
)
6678 colors
[j
++] = p
->pixel
;
6686 /***********************************************************************
6688 ***********************************************************************/
6690 static XColor
*x_to_xcolors
P_ ((struct frame
*, struct image
*, int));
6691 static void x_from_xcolors
P_ ((struct frame
*, struct image
*, XColor
*));
6692 static void x_detect_edges
P_ ((struct frame
*, struct image
*, int[9], int));
6694 /* Non-zero means draw a cross on images having `:conversion
6697 int cross_disabled_images
;
6699 /* Edge detection matrices for different edge-detection
6702 static int emboss_matrix
[9] = {
6704 2, -1, 0, /* y - 1 */
6706 0, 1, -2 /* y + 1 */
6709 static int laplace_matrix
[9] = {
6711 1, 0, 0, /* y - 1 */
6713 0, 0, -1 /* y + 1 */
6716 /* Value is the intensity of the color whose red/green/blue values
6719 #define COLOR_INTENSITY(R, G, B) ((2 * (R) + 3 * (G) + (B)) / 6)
6722 /* On frame F, return an array of XColor structures describing image
6723 IMG->pixmap. Each XColor structure has its pixel color set. RGB_P
6724 non-zero means also fill the red/green/blue members of the XColor
6725 structures. Value is a pointer to the array of XColors structures,
6726 allocated with xmalloc; it must be freed by the caller. */
6729 x_to_xcolors (f
, img
, rgb_p
)
6738 colors
= (XColor
*) xmalloc (img
->width
* img
->height
* sizeof *colors
);
6740 /* Get the X image IMG->pixmap. */
6741 ximg
= XGetImage (FRAME_X_DISPLAY (f
), img
->pixmap
,
6742 0, 0, img
->width
, img
->height
, ~0, ZPixmap
);
6744 /* Fill the `pixel' members of the XColor array. I wished there
6745 were an easy and portable way to circumvent XGetPixel. */
6747 for (y
= 0; y
< img
->height
; ++y
)
6751 for (x
= 0; x
< img
->width
; ++x
, ++p
)
6752 p
->pixel
= XGetPixel (ximg
, x
, y
);
6755 x_query_colors (f
, row
, img
->width
);
6758 XDestroyImage (ximg
);
6763 /* Create IMG->pixmap from an array COLORS of XColor structures, whose
6764 RGB members are set. F is the frame on which this all happens.
6765 COLORS will be freed; an existing IMG->pixmap will be freed, too. */
6768 x_from_xcolors (f
, img
, colors
)
6778 init_color_table ();
6780 x_create_x_image_and_pixmap (f
, img
->width
, img
->height
, 0,
6783 for (y
= 0; y
< img
->height
; ++y
)
6784 for (x
= 0; x
< img
->width
; ++x
, ++p
)
6786 unsigned long pixel
;
6787 pixel
= lookup_rgb_color (f
, p
->red
, p
->green
, p
->blue
);
6788 XPutPixel (oimg
, x
, y
, pixel
);
6792 x_clear_image_1 (f
, img
, 1, 0, 1);
6794 x_put_x_image (f
, oimg
, pixmap
, img
->width
, img
->height
);
6795 x_destroy_x_image (oimg
);
6796 img
->pixmap
= pixmap
;
6797 img
->colors
= colors_in_color_table (&img
->ncolors
);
6798 free_color_table ();
6802 /* On frame F, perform edge-detection on image IMG.
6804 MATRIX is a nine-element array specifying the transformation
6805 matrix. See emboss_matrix for an example.
6807 COLOR_ADJUST is a color adjustment added to each pixel of the
6811 x_detect_edges (f
, img
, matrix
, color_adjust
)
6814 int matrix
[9], color_adjust
;
6816 XColor
*colors
= x_to_xcolors (f
, img
, 1);
6820 for (i
= sum
= 0; i
< 9; ++i
)
6821 sum
+= abs (matrix
[i
]);
6823 #define COLOR(A, X, Y) ((A) + (Y) * img->width + (X))
6825 new = (XColor
*) xmalloc (img
->width
* img
->height
* sizeof *new);
6827 for (y
= 0; y
< img
->height
; ++y
)
6829 p
= COLOR (new, 0, y
);
6830 p
->red
= p
->green
= p
->blue
= 0xffff/2;
6831 p
= COLOR (new, img
->width
- 1, y
);
6832 p
->red
= p
->green
= p
->blue
= 0xffff/2;
6835 for (x
= 1; x
< img
->width
- 1; ++x
)
6837 p
= COLOR (new, x
, 0);
6838 p
->red
= p
->green
= p
->blue
= 0xffff/2;
6839 p
= COLOR (new, x
, img
->height
- 1);
6840 p
->red
= p
->green
= p
->blue
= 0xffff/2;
6843 for (y
= 1; y
< img
->height
- 1; ++y
)
6845 p
= COLOR (new, 1, y
);
6847 for (x
= 1; x
< img
->width
- 1; ++x
, ++p
)
6849 int r
, g
, b
, y1
, x1
;
6852 for (y1
= y
- 1; y1
< y
+ 2; ++y1
)
6853 for (x1
= x
- 1; x1
< x
+ 2; ++x1
, ++i
)
6856 XColor
*t
= COLOR (colors
, x1
, y1
);
6857 r
+= matrix
[i
] * t
->red
;
6858 g
+= matrix
[i
] * t
->green
;
6859 b
+= matrix
[i
] * t
->blue
;
6862 r
= (r
/ sum
+ color_adjust
) & 0xffff;
6863 g
= (g
/ sum
+ color_adjust
) & 0xffff;
6864 b
= (b
/ sum
+ color_adjust
) & 0xffff;
6865 p
->red
= p
->green
= p
->blue
= COLOR_INTENSITY (r
, g
, b
);
6870 x_from_xcolors (f
, img
, new);
6876 /* Perform the pre-defined `emboss' edge-detection on image IMG
6884 x_detect_edges (f
, img
, emboss_matrix
, 0xffff / 2);
6888 /* Perform the pre-defined `laplace' edge-detection on image IMG
6896 x_detect_edges (f
, img
, laplace_matrix
, 45000);
6900 /* Perform edge-detection on image IMG on frame F, with specified
6901 transformation matrix MATRIX and color-adjustment COLOR_ADJUST.
6903 MATRIX must be either
6905 - a list of at least 9 numbers in row-major form
6906 - a vector of at least 9 numbers
6908 COLOR_ADJUST nil means use a default; otherwise it must be a
6912 x_edge_detection (f
, img
, matrix
, color_adjust
)
6915 Lisp_Object matrix
, color_adjust
;
6923 i
< 9 && CONSP (matrix
) && NUMBERP (XCAR (matrix
));
6924 ++i
, matrix
= XCDR (matrix
))
6925 trans
[i
] = XFLOATINT (XCAR (matrix
));
6927 else if (VECTORP (matrix
) && ASIZE (matrix
) >= 9)
6929 for (i
= 0; i
< 9 && NUMBERP (AREF (matrix
, i
)); ++i
)
6930 trans
[i
] = XFLOATINT (AREF (matrix
, i
));
6933 if (NILP (color_adjust
))
6934 color_adjust
= make_number (0xffff / 2);
6936 if (i
== 9 && NUMBERP (color_adjust
))
6937 x_detect_edges (f
, img
, trans
, (int) XFLOATINT (color_adjust
));
6941 /* Transform image IMG on frame F so that it looks disabled. */
6944 x_disable_image (f
, img
)
6948 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
6950 if (dpyinfo
->n_planes
>= 2)
6952 /* Color (or grayscale). Convert to gray, and equalize. Just
6953 drawing such images with a stipple can look very odd, so
6954 we're using this method instead. */
6955 XColor
*colors
= x_to_xcolors (f
, img
, 1);
6957 const int h
= 15000;
6958 const int l
= 30000;
6960 for (p
= colors
, end
= colors
+ img
->width
* img
->height
;
6964 int i
= COLOR_INTENSITY (p
->red
, p
->green
, p
->blue
);
6965 int i2
= (0xffff - h
- l
) * i
/ 0xffff + l
;
6966 p
->red
= p
->green
= p
->blue
= i2
;
6969 x_from_xcolors (f
, img
, colors
);
6972 /* Draw a cross over the disabled image, if we must or if we
6974 if (dpyinfo
->n_planes
< 2 || cross_disabled_images
)
6976 Display
*dpy
= FRAME_X_DISPLAY (f
);
6979 gc
= XCreateGC (dpy
, img
->pixmap
, 0, NULL
);
6980 XSetForeground (dpy
, gc
, BLACK_PIX_DEFAULT (f
));
6981 XDrawLine (dpy
, img
->pixmap
, gc
, 0, 0,
6982 img
->width
- 1, img
->height
- 1);
6983 XDrawLine (dpy
, img
->pixmap
, gc
, 0, img
->height
- 1,
6989 gc
= XCreateGC (dpy
, img
->mask
, 0, NULL
);
6990 XSetForeground (dpy
, gc
, WHITE_PIX_DEFAULT (f
));
6991 XDrawLine (dpy
, img
->mask
, gc
, 0, 0,
6992 img
->width
- 1, img
->height
- 1);
6993 XDrawLine (dpy
, img
->mask
, gc
, 0, img
->height
- 1,
7001 /* Build a mask for image IMG which is used on frame F. FILE is the
7002 name of an image file, for error messages. HOW determines how to
7003 determine the background color of IMG. If it is a list '(R G B)',
7004 with R, G, and B being integers >= 0, take that as the color of the
7005 background. Otherwise, determine the background color of IMG
7006 heuristically. Value is non-zero if successful. */
7009 x_build_heuristic_mask (f
, img
, how
)
7014 Display
*dpy
= FRAME_X_DISPLAY (f
);
7015 XImage
*ximg
, *mask_img
;
7016 int x
, y
, rc
, use_img_background
;
7017 unsigned long bg
= 0;
7021 XFreePixmap (FRAME_X_DISPLAY (f
), img
->mask
);
7023 img
->background_transparent_valid
= 0;
7026 /* Create an image and pixmap serving as mask. */
7027 rc
= x_create_x_image_and_pixmap (f
, img
->width
, img
->height
, 1,
7028 &mask_img
, &img
->mask
);
7032 /* Get the X image of IMG->pixmap. */
7033 ximg
= XGetImage (dpy
, img
->pixmap
, 0, 0, img
->width
, img
->height
,
7036 /* Determine the background color of ximg. If HOW is `(R G B)'
7037 take that as color. Otherwise, use the image's background color. */
7038 use_img_background
= 1;
7044 for (i
= 0; i
< 3 && CONSP (how
) && NATNUMP (XCAR (how
)); ++i
)
7046 rgb
[i
] = XFASTINT (XCAR (how
)) & 0xffff;
7050 if (i
== 3 && NILP (how
))
7052 char color_name
[30];
7053 sprintf (color_name
, "#%04x%04x%04x", rgb
[0], rgb
[1], rgb
[2]);
7054 bg
= x_alloc_image_color (f
, img
, build_string (color_name
), 0);
7055 use_img_background
= 0;
7059 if (use_img_background
)
7060 bg
= four_corners_best (ximg
, img
->width
, img
->height
);
7062 /* Set all bits in mask_img to 1 whose color in ximg is different
7063 from the background color bg. */
7064 for (y
= 0; y
< img
->height
; ++y
)
7065 for (x
= 0; x
< img
->width
; ++x
)
7066 XPutPixel (mask_img
, x
, y
, XGetPixel (ximg
, x
, y
) != bg
);
7068 /* Fill in the background_transparent field while we have the mask handy. */
7069 image_background_transparent (img
, f
, mask_img
);
7071 /* Put mask_img into img->mask. */
7072 x_put_x_image (f
, mask_img
, img
->mask
, img
->width
, img
->height
);
7073 x_destroy_x_image (mask_img
);
7074 XDestroyImage (ximg
);
7081 /***********************************************************************
7082 PBM (mono, gray, color)
7083 ***********************************************************************/
7085 static int pbm_image_p
P_ ((Lisp_Object object
));
7086 static int pbm_load
P_ ((struct frame
*f
, struct image
*img
));
7087 static int pbm_scan_number
P_ ((unsigned char **, unsigned char *));
7089 /* The symbol `pbm' identifying images of this type. */
7093 /* Indices of image specification fields in gs_format, below. */
7095 enum pbm_keyword_index
7111 /* Vector of image_keyword structures describing the format
7112 of valid user-defined image specifications. */
7114 static struct image_keyword pbm_format
[PBM_LAST
] =
7116 {":type", IMAGE_SYMBOL_VALUE
, 1},
7117 {":file", IMAGE_STRING_VALUE
, 0},
7118 {":data", IMAGE_STRING_VALUE
, 0},
7119 {":ascent", IMAGE_ASCENT_VALUE
, 0},
7120 {":margin", IMAGE_POSITIVE_INTEGER_VALUE_OR_PAIR
, 0},
7121 {":relief", IMAGE_INTEGER_VALUE
, 0},
7122 {":conversion", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
7123 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
7124 {":mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
7125 {":foreground", IMAGE_STRING_OR_NIL_VALUE
, 0},
7126 {":background", IMAGE_STRING_OR_NIL_VALUE
, 0}
7129 /* Structure describing the image type `pbm'. */
7131 static struct image_type pbm_type
=
7141 /* Return non-zero if OBJECT is a valid PBM image specification. */
7144 pbm_image_p (object
)
7147 struct image_keyword fmt
[PBM_LAST
];
7149 bcopy (pbm_format
, fmt
, sizeof fmt
);
7151 if (!parse_image_spec (object
, fmt
, PBM_LAST
, Qpbm
))
7154 /* Must specify either :data or :file. */
7155 return fmt
[PBM_DATA
].count
+ fmt
[PBM_FILE
].count
== 1;
7159 /* Scan a decimal number from *S and return it. Advance *S while
7160 reading the number. END is the end of the string. Value is -1 at
7164 pbm_scan_number (s
, end
)
7165 unsigned char **s
, *end
;
7167 int c
= 0, val
= -1;
7171 /* Skip white-space. */
7172 while (*s
< end
&& (c
= *(*s
)++, isspace (c
)))
7177 /* Skip comment to end of line. */
7178 while (*s
< end
&& (c
= *(*s
)++, c
!= '\n'))
7181 else if (isdigit (c
))
7183 /* Read decimal number. */
7185 while (*s
< end
&& (c
= *(*s
)++, isdigit (c
)))
7186 val
= 10 * val
+ c
- '0';
7197 /* Load PBM image IMG for use on frame F. */
7205 int width
, height
, max_color_idx
= 0;
7207 Lisp_Object file
, specified_file
;
7208 enum {PBM_MONO
, PBM_GRAY
, PBM_COLOR
} type
;
7209 struct gcpro gcpro1
;
7210 unsigned char *contents
= NULL
;
7211 unsigned char *end
, *p
;
7214 specified_file
= image_spec_value (img
->spec
, QCfile
, NULL
);
7218 if (STRINGP (specified_file
))
7220 file
= x_find_image_file (specified_file
);
7221 if (!STRINGP (file
))
7223 image_error ("Cannot find image file `%s'", specified_file
, Qnil
);
7228 contents
= slurp_file (SDATA (file
), &size
);
7229 if (contents
== NULL
)
7231 image_error ("Error reading `%s'", file
, Qnil
);
7237 end
= contents
+ size
;
7242 data
= image_spec_value (img
->spec
, QCdata
, NULL
);
7244 end
= p
+ SBYTES (data
);
7247 /* Check magic number. */
7248 if (end
- p
< 2 || *p
++ != 'P')
7250 image_error ("Not a PBM image: `%s'", img
->spec
, Qnil
);
7260 raw_p
= 0, type
= PBM_MONO
;
7264 raw_p
= 0, type
= PBM_GRAY
;
7268 raw_p
= 0, type
= PBM_COLOR
;
7272 raw_p
= 1, type
= PBM_MONO
;
7276 raw_p
= 1, type
= PBM_GRAY
;
7280 raw_p
= 1, type
= PBM_COLOR
;
7284 image_error ("Not a PBM image: `%s'", img
->spec
, Qnil
);
7288 /* Read width, height, maximum color-component. Characters
7289 starting with `#' up to the end of a line are ignored. */
7290 width
= pbm_scan_number (&p
, end
);
7291 height
= pbm_scan_number (&p
, end
);
7293 if (type
!= PBM_MONO
)
7295 max_color_idx
= pbm_scan_number (&p
, end
);
7296 if (raw_p
&& max_color_idx
> 255)
7297 max_color_idx
= 255;
7302 || (type
!= PBM_MONO
&& max_color_idx
< 0))
7305 if (!x_create_x_image_and_pixmap (f
, width
, height
, 0,
7306 &ximg
, &img
->pixmap
))
7309 /* Initialize the color hash table. */
7310 init_color_table ();
7312 if (type
== PBM_MONO
)
7315 struct image_keyword fmt
[PBM_LAST
];
7316 unsigned long fg
= FRAME_FOREGROUND_PIXEL (f
);
7317 unsigned long bg
= FRAME_BACKGROUND_PIXEL (f
);
7319 /* Parse the image specification. */
7320 bcopy (pbm_format
, fmt
, sizeof fmt
);
7321 parse_image_spec (img
->spec
, fmt
, PBM_LAST
, Qpbm
);
7323 /* Get foreground and background colors, maybe allocate colors. */
7324 if (fmt
[PBM_FOREGROUND
].count
7325 && STRINGP (fmt
[PBM_FOREGROUND
].value
))
7326 fg
= x_alloc_image_color (f
, img
, fmt
[PBM_FOREGROUND
].value
, fg
);
7327 if (fmt
[PBM_BACKGROUND
].count
7328 && STRINGP (fmt
[PBM_BACKGROUND
].value
))
7330 bg
= x_alloc_image_color (f
, img
, fmt
[PBM_BACKGROUND
].value
, bg
);
7331 img
->background
= bg
;
7332 img
->background_valid
= 1;
7335 for (y
= 0; y
< height
; ++y
)
7336 for (x
= 0; x
< width
; ++x
)
7346 g
= pbm_scan_number (&p
, end
);
7348 XPutPixel (ximg
, x
, y
, g
? fg
: bg
);
7353 for (y
= 0; y
< height
; ++y
)
7354 for (x
= 0; x
< width
; ++x
)
7358 if (type
== PBM_GRAY
)
7359 r
= g
= b
= raw_p
? *p
++ : pbm_scan_number (&p
, end
);
7368 r
= pbm_scan_number (&p
, end
);
7369 g
= pbm_scan_number (&p
, end
);
7370 b
= pbm_scan_number (&p
, end
);
7373 if (r
< 0 || g
< 0 || b
< 0)
7377 XDestroyImage (ximg
);
7378 image_error ("Invalid pixel value in image `%s'",
7383 /* RGB values are now in the range 0..max_color_idx.
7384 Scale this to the range 0..0xffff supported by X. */
7385 r
= (double) r
* 65535 / max_color_idx
;
7386 g
= (double) g
* 65535 / max_color_idx
;
7387 b
= (double) b
* 65535 / max_color_idx
;
7388 XPutPixel (ximg
, x
, y
, lookup_rgb_color (f
, r
, g
, b
));
7392 /* Store in IMG->colors the colors allocated for the image, and
7393 free the color table. */
7394 img
->colors
= colors_in_color_table (&img
->ncolors
);
7395 free_color_table ();
7397 /* Maybe fill in the background field while we have ximg handy. */
7398 if (NILP (image_spec_value (img
->spec
, QCbackground
, NULL
)))
7399 IMAGE_BACKGROUND (img
, f
, ximg
);
7401 /* Put the image into a pixmap. */
7402 x_put_x_image (f
, ximg
, img
->pixmap
, width
, height
);
7403 x_destroy_x_image (ximg
);
7406 img
->height
= height
;
7415 /***********************************************************************
7417 ***********************************************************************/
7423 /* Function prototypes. */
7425 static int png_image_p
P_ ((Lisp_Object object
));
7426 static int png_load
P_ ((struct frame
*f
, struct image
*img
));
7428 /* The symbol `png' identifying images of this type. */
7432 /* Indices of image specification fields in png_format, below. */
7434 enum png_keyword_index
7449 /* Vector of image_keyword structures describing the format
7450 of valid user-defined image specifications. */
7452 static struct image_keyword png_format
[PNG_LAST
] =
7454 {":type", IMAGE_SYMBOL_VALUE
, 1},
7455 {":data", IMAGE_STRING_VALUE
, 0},
7456 {":file", IMAGE_STRING_VALUE
, 0},
7457 {":ascent", IMAGE_ASCENT_VALUE
, 0},
7458 {":margin", IMAGE_POSITIVE_INTEGER_VALUE_OR_PAIR
, 0},
7459 {":relief", IMAGE_INTEGER_VALUE
, 0},
7460 {":conversion", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
7461 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
7462 {":mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
7463 {":background", IMAGE_STRING_OR_NIL_VALUE
, 0}
7466 /* Structure describing the image type `png'. */
7468 static struct image_type png_type
=
7478 /* Return non-zero if OBJECT is a valid PNG image specification. */
7481 png_image_p (object
)
7484 struct image_keyword fmt
[PNG_LAST
];
7485 bcopy (png_format
, fmt
, sizeof fmt
);
7487 if (!parse_image_spec (object
, fmt
, PNG_LAST
, Qpng
))
7490 /* Must specify either the :data or :file keyword. */
7491 return fmt
[PNG_FILE
].count
+ fmt
[PNG_DATA
].count
== 1;
7495 /* Error and warning handlers installed when the PNG library
7499 my_png_error (png_ptr
, msg
)
7500 png_struct
*png_ptr
;
7503 xassert (png_ptr
!= NULL
);
7504 image_error ("PNG error: %s", build_string (msg
), Qnil
);
7505 longjmp (png_ptr
->jmpbuf
, 1);
7510 my_png_warning (png_ptr
, msg
)
7511 png_struct
*png_ptr
;
7514 xassert (png_ptr
!= NULL
);
7515 image_error ("PNG warning: %s", build_string (msg
), Qnil
);
7518 /* Memory source for PNG decoding. */
7520 struct png_memory_storage
7522 unsigned char *bytes
; /* The data */
7523 size_t len
; /* How big is it? */
7524 int index
; /* Where are we? */
7528 /* Function set as reader function when reading PNG image from memory.
7529 PNG_PTR is a pointer to the PNG control structure. Copy LENGTH
7530 bytes from the input to DATA. */
7533 png_read_from_memory (png_ptr
, data
, length
)
7534 png_structp png_ptr
;
7538 struct png_memory_storage
*tbr
7539 = (struct png_memory_storage
*) png_get_io_ptr (png_ptr
);
7541 if (length
> tbr
->len
- tbr
->index
)
7542 png_error (png_ptr
, "Read error");
7544 bcopy (tbr
->bytes
+ tbr
->index
, data
, length
);
7545 tbr
->index
= tbr
->index
+ length
;
7548 /* Load PNG image IMG for use on frame F. Value is non-zero if
7556 Lisp_Object file
, specified_file
;
7557 Lisp_Object specified_data
;
7559 XImage
*ximg
, *mask_img
= NULL
;
7560 struct gcpro gcpro1
;
7561 png_struct
*png_ptr
= NULL
;
7562 png_info
*info_ptr
= NULL
, *end_info
= NULL
;
7563 FILE *volatile fp
= NULL
;
7565 png_byte
* volatile pixels
= NULL
;
7566 png_byte
** volatile rows
= NULL
;
7567 png_uint_32 width
, height
;
7568 int bit_depth
, color_type
, interlace_type
;
7570 png_uint_32 row_bytes
;
7572 double screen_gamma
, image_gamma
;
7574 struct png_memory_storage tbr
; /* Data to be read */
7576 /* Find out what file to load. */
7577 specified_file
= image_spec_value (img
->spec
, QCfile
, NULL
);
7578 specified_data
= image_spec_value (img
->spec
, QCdata
, NULL
);
7582 if (NILP (specified_data
))
7584 file
= x_find_image_file (specified_file
);
7585 if (!STRINGP (file
))
7587 image_error ("Cannot find image file `%s'", specified_file
, Qnil
);
7592 /* Open the image file. */
7593 fp
= fopen (SDATA (file
), "rb");
7596 image_error ("Cannot open image file `%s'", file
, Qnil
);
7602 /* Check PNG signature. */
7603 if (fread (sig
, 1, sizeof sig
, fp
) != sizeof sig
7604 || !png_check_sig (sig
, sizeof sig
))
7606 image_error ("Not a PNG file: `%s'", file
, Qnil
);
7614 /* Read from memory. */
7615 tbr
.bytes
= SDATA (specified_data
);
7616 tbr
.len
= SBYTES (specified_data
);
7619 /* Check PNG signature. */
7620 if (tbr
.len
< sizeof sig
7621 || !png_check_sig (tbr
.bytes
, sizeof sig
))
7623 image_error ("Not a PNG image: `%s'", img
->spec
, Qnil
);
7628 /* Need to skip past the signature. */
7629 tbr
.bytes
+= sizeof (sig
);
7632 /* Initialize read and info structs for PNG lib. */
7633 png_ptr
= png_create_read_struct (PNG_LIBPNG_VER_STRING
, NULL
,
7634 my_png_error
, my_png_warning
);
7637 if (fp
) fclose (fp
);
7642 info_ptr
= png_create_info_struct (png_ptr
);
7645 png_destroy_read_struct (&png_ptr
, NULL
, NULL
);
7646 if (fp
) fclose (fp
);
7651 end_info
= png_create_info_struct (png_ptr
);
7654 png_destroy_read_struct (&png_ptr
, &info_ptr
, NULL
);
7655 if (fp
) fclose (fp
);
7660 /* Set error jump-back. We come back here when the PNG library
7661 detects an error. */
7662 if (setjmp (png_ptr
->jmpbuf
))
7666 png_destroy_read_struct (&png_ptr
, &info_ptr
, &end_info
);
7669 if (fp
) fclose (fp
);
7674 /* Read image info. */
7675 if (!NILP (specified_data
))
7676 png_set_read_fn (png_ptr
, (void *) &tbr
, png_read_from_memory
);
7678 png_init_io (png_ptr
, fp
);
7680 png_set_sig_bytes (png_ptr
, sizeof sig
);
7681 png_read_info (png_ptr
, info_ptr
);
7682 png_get_IHDR (png_ptr
, info_ptr
, &width
, &height
, &bit_depth
, &color_type
,
7683 &interlace_type
, NULL
, NULL
);
7685 /* If image contains simply transparency data, we prefer to
7686 construct a clipping mask. */
7687 if (png_get_valid (png_ptr
, info_ptr
, PNG_INFO_tRNS
))
7692 /* This function is easier to write if we only have to handle
7693 one data format: RGB or RGBA with 8 bits per channel. Let's
7694 transform other formats into that format. */
7696 /* Strip more than 8 bits per channel. */
7697 if (bit_depth
== 16)
7698 png_set_strip_16 (png_ptr
);
7700 /* Expand data to 24 bit RGB, or 8 bit grayscale, with alpha channel
7702 png_set_expand (png_ptr
);
7704 /* Convert grayscale images to RGB. */
7705 if (color_type
== PNG_COLOR_TYPE_GRAY
7706 || color_type
== PNG_COLOR_TYPE_GRAY_ALPHA
)
7707 png_set_gray_to_rgb (png_ptr
);
7709 screen_gamma
= (f
->gamma
? 1 / f
->gamma
/ 0.45455 : 2.2);
7711 #if 0 /* Avoid double gamma correction for PNG images. */
7712 /* Tell the PNG lib to handle gamma correction for us. */
7713 #if defined(PNG_READ_sRGB_SUPPORTED) || defined(PNG_WRITE_sRGB_SUPPORTED)
7714 if (png_get_sRGB (png_ptr
, info_ptr
, &intent
))
7715 /* The libpng documentation says this is right in this case. */
7716 png_set_gamma (png_ptr
, screen_gamma
, 0.45455);
7719 if (png_get_gAMA (png_ptr
, info_ptr
, &image_gamma
))
7720 /* Image contains gamma information. */
7721 png_set_gamma (png_ptr
, screen_gamma
, image_gamma
);
7723 /* Use the standard default for the image gamma. */
7724 png_set_gamma (png_ptr
, screen_gamma
, 0.45455);
7727 /* Handle alpha channel by combining the image with a background
7728 color. Do this only if a real alpha channel is supplied. For
7729 simple transparency, we prefer a clipping mask. */
7732 png_color_16
*image_bg
;
7733 Lisp_Object specified_bg
7734 = image_spec_value (img
->spec
, QCbackground
, NULL
);
7736 if (STRINGP (specified_bg
))
7737 /* The user specified `:background', use that. */
7740 if (x_defined_color (f
, SDATA (specified_bg
), &color
, 0))
7742 png_color_16 user_bg
;
7744 bzero (&user_bg
, sizeof user_bg
);
7745 user_bg
.red
= color
.red
;
7746 user_bg
.green
= color
.green
;
7747 user_bg
.blue
= color
.blue
;
7749 png_set_background (png_ptr
, &user_bg
,
7750 PNG_BACKGROUND_GAMMA_SCREEN
, 0, 1.0);
7753 else if (png_get_bKGD (png_ptr
, info_ptr
, &image_bg
))
7754 /* Image contains a background color with which to
7755 combine the image. */
7756 png_set_background (png_ptr
, image_bg
,
7757 PNG_BACKGROUND_GAMMA_FILE
, 1, 1.0);
7760 /* Image does not contain a background color with which
7761 to combine the image data via an alpha channel. Use
7762 the frame's background instead. */
7765 png_color_16 frame_background
;
7767 cmap
= FRAME_X_COLORMAP (f
);
7768 color
.pixel
= FRAME_BACKGROUND_PIXEL (f
);
7769 x_query_color (f
, &color
);
7771 bzero (&frame_background
, sizeof frame_background
);
7772 frame_background
.red
= color
.red
;
7773 frame_background
.green
= color
.green
;
7774 frame_background
.blue
= color
.blue
;
7776 png_set_background (png_ptr
, &frame_background
,
7777 PNG_BACKGROUND_GAMMA_SCREEN
, 0, 1.0);
7781 /* Update info structure. */
7782 png_read_update_info (png_ptr
, info_ptr
);
7784 /* Get number of channels. Valid values are 1 for grayscale images
7785 and images with a palette, 2 for grayscale images with transparency
7786 information (alpha channel), 3 for RGB images, and 4 for RGB
7787 images with alpha channel, i.e. RGBA. If conversions above were
7788 sufficient we should only have 3 or 4 channels here. */
7789 channels
= png_get_channels (png_ptr
, info_ptr
);
7790 xassert (channels
== 3 || channels
== 4);
7792 /* Number of bytes needed for one row of the image. */
7793 row_bytes
= png_get_rowbytes (png_ptr
, info_ptr
);
7795 /* Allocate memory for the image. */
7796 pixels
= (png_byte
*) xmalloc (row_bytes
* height
* sizeof *pixels
);
7797 rows
= (png_byte
**) xmalloc (height
* sizeof *rows
);
7798 for (i
= 0; i
< height
; ++i
)
7799 rows
[i
] = pixels
+ i
* row_bytes
;
7801 /* Read the entire image. */
7802 png_read_image (png_ptr
, rows
);
7803 png_read_end (png_ptr
, info_ptr
);
7810 /* Create the X image and pixmap. */
7811 if (!x_create_x_image_and_pixmap (f
, width
, height
, 0, &ximg
,
7815 /* Create an image and pixmap serving as mask if the PNG image
7816 contains an alpha channel. */
7819 && !x_create_x_image_and_pixmap (f
, width
, height
, 1,
7820 &mask_img
, &img
->mask
))
7822 x_destroy_x_image (ximg
);
7823 XFreePixmap (FRAME_X_DISPLAY (f
), img
->pixmap
);
7828 /* Fill the X image and mask from PNG data. */
7829 init_color_table ();
7831 for (y
= 0; y
< height
; ++y
)
7833 png_byte
*p
= rows
[y
];
7835 for (x
= 0; x
< width
; ++x
)
7842 XPutPixel (ximg
, x
, y
, lookup_rgb_color (f
, r
, g
, b
));
7844 /* An alpha channel, aka mask channel, associates variable
7845 transparency with an image. Where other image formats
7846 support binary transparency---fully transparent or fully
7847 opaque---PNG allows up to 254 levels of partial transparency.
7848 The PNG library implements partial transparency by combining
7849 the image with a specified background color.
7851 I'm not sure how to handle this here nicely: because the
7852 background on which the image is displayed may change, for
7853 real alpha channel support, it would be necessary to create
7854 a new image for each possible background.
7856 What I'm doing now is that a mask is created if we have
7857 boolean transparency information. Otherwise I'm using
7858 the frame's background color to combine the image with. */
7863 XPutPixel (mask_img
, x
, y
, *p
> 0);
7869 if (NILP (image_spec_value (img
->spec
, QCbackground
, NULL
)))
7870 /* Set IMG's background color from the PNG image, unless the user
7874 if (png_get_bKGD (png_ptr
, info_ptr
, &bg
))
7876 img
->background
= lookup_rgb_color (f
, bg
->red
, bg
->green
, bg
->blue
);
7877 img
->background_valid
= 1;
7881 /* Remember colors allocated for this image. */
7882 img
->colors
= colors_in_color_table (&img
->ncolors
);
7883 free_color_table ();
7886 png_destroy_read_struct (&png_ptr
, &info_ptr
, &end_info
);
7891 img
->height
= height
;
7893 /* Maybe fill in the background field while we have ximg handy. */
7894 IMAGE_BACKGROUND (img
, f
, ximg
);
7896 /* Put the image into the pixmap, then free the X image and its buffer. */
7897 x_put_x_image (f
, ximg
, img
->pixmap
, width
, height
);
7898 x_destroy_x_image (ximg
);
7900 /* Same for the mask. */
7903 /* Fill in the background_transparent field while we have the mask
7905 image_background_transparent (img
, f
, mask_img
);
7907 x_put_x_image (f
, mask_img
, img
->mask
, img
->width
, img
->height
);
7908 x_destroy_x_image (mask_img
);
7915 #endif /* HAVE_PNG != 0 */
7919 /***********************************************************************
7921 ***********************************************************************/
7925 /* Work around a warning about HAVE_STDLIB_H being redefined in
7927 #ifdef HAVE_STDLIB_H
7928 #define HAVE_STDLIB_H_1
7929 #undef HAVE_STDLIB_H
7930 #endif /* HAVE_STLIB_H */
7932 #include <jpeglib.h>
7936 #ifdef HAVE_STLIB_H_1
7937 #define HAVE_STDLIB_H 1
7940 static int jpeg_image_p
P_ ((Lisp_Object object
));
7941 static int jpeg_load
P_ ((struct frame
*f
, struct image
*img
));
7943 /* The symbol `jpeg' identifying images of this type. */
7947 /* Indices of image specification fields in gs_format, below. */
7949 enum jpeg_keyword_index
7958 JPEG_HEURISTIC_MASK
,
7964 /* Vector of image_keyword structures describing the format
7965 of valid user-defined image specifications. */
7967 static struct image_keyword jpeg_format
[JPEG_LAST
] =
7969 {":type", IMAGE_SYMBOL_VALUE
, 1},
7970 {":data", IMAGE_STRING_VALUE
, 0},
7971 {":file", IMAGE_STRING_VALUE
, 0},
7972 {":ascent", IMAGE_ASCENT_VALUE
, 0},
7973 {":margin", IMAGE_POSITIVE_INTEGER_VALUE_OR_PAIR
, 0},
7974 {":relief", IMAGE_INTEGER_VALUE
, 0},
7975 {":conversions", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
7976 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
7977 {":mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
7978 {":background", IMAGE_STRING_OR_NIL_VALUE
, 0}
7981 /* Structure describing the image type `jpeg'. */
7983 static struct image_type jpeg_type
=
7993 /* Return non-zero if OBJECT is a valid JPEG image specification. */
7996 jpeg_image_p (object
)
7999 struct image_keyword fmt
[JPEG_LAST
];
8001 bcopy (jpeg_format
, fmt
, sizeof fmt
);
8003 if (!parse_image_spec (object
, fmt
, JPEG_LAST
, Qjpeg
))
8006 /* Must specify either the :data or :file keyword. */
8007 return fmt
[JPEG_FILE
].count
+ fmt
[JPEG_DATA
].count
== 1;
8011 struct my_jpeg_error_mgr
8013 struct jpeg_error_mgr pub
;
8014 jmp_buf setjmp_buffer
;
8019 my_error_exit (cinfo
)
8022 struct my_jpeg_error_mgr
*mgr
= (struct my_jpeg_error_mgr
*) cinfo
->err
;
8023 longjmp (mgr
->setjmp_buffer
, 1);
8027 /* Init source method for JPEG data source manager. Called by
8028 jpeg_read_header() before any data is actually read. See
8029 libjpeg.doc from the JPEG lib distribution. */
8032 our_init_source (cinfo
)
8033 j_decompress_ptr cinfo
;
8038 /* Fill input buffer method for JPEG data source manager. Called
8039 whenever more data is needed. We read the whole image in one step,
8040 so this only adds a fake end of input marker at the end. */
8043 our_fill_input_buffer (cinfo
)
8044 j_decompress_ptr cinfo
;
8046 /* Insert a fake EOI marker. */
8047 struct jpeg_source_mgr
*src
= cinfo
->src
;
8048 static JOCTET buffer
[2];
8050 buffer
[0] = (JOCTET
) 0xFF;
8051 buffer
[1] = (JOCTET
) JPEG_EOI
;
8053 src
->next_input_byte
= buffer
;
8054 src
->bytes_in_buffer
= 2;
8059 /* Method to skip over NUM_BYTES bytes in the image data. CINFO->src
8060 is the JPEG data source manager. */
8063 our_skip_input_data (cinfo
, num_bytes
)
8064 j_decompress_ptr cinfo
;
8067 struct jpeg_source_mgr
*src
= (struct jpeg_source_mgr
*) cinfo
->src
;
8071 if (num_bytes
> src
->bytes_in_buffer
)
8072 ERREXIT (cinfo
, JERR_INPUT_EOF
);
8074 src
->bytes_in_buffer
-= num_bytes
;
8075 src
->next_input_byte
+= num_bytes
;
8080 /* Method to terminate data source. Called by
8081 jpeg_finish_decompress() after all data has been processed. */
8084 our_term_source (cinfo
)
8085 j_decompress_ptr cinfo
;
8090 /* Set up the JPEG lib for reading an image from DATA which contains
8091 LEN bytes. CINFO is the decompression info structure created for
8092 reading the image. */
8095 jpeg_memory_src (cinfo
, data
, len
)
8096 j_decompress_ptr cinfo
;
8100 struct jpeg_source_mgr
*src
;
8102 if (cinfo
->src
== NULL
)
8104 /* First time for this JPEG object? */
8105 cinfo
->src
= (struct jpeg_source_mgr
*)
8106 (*cinfo
->mem
->alloc_small
) ((j_common_ptr
) cinfo
, JPOOL_PERMANENT
,
8107 sizeof (struct jpeg_source_mgr
));
8108 src
= (struct jpeg_source_mgr
*) cinfo
->src
;
8109 src
->next_input_byte
= data
;
8112 src
= (struct jpeg_source_mgr
*) cinfo
->src
;
8113 src
->init_source
= our_init_source
;
8114 src
->fill_input_buffer
= our_fill_input_buffer
;
8115 src
->skip_input_data
= our_skip_input_data
;
8116 src
->resync_to_restart
= jpeg_resync_to_restart
; /* Use default method. */
8117 src
->term_source
= our_term_source
;
8118 src
->bytes_in_buffer
= len
;
8119 src
->next_input_byte
= data
;
8123 /* Load image IMG for use on frame F. Patterned after example.c
8124 from the JPEG lib. */
8131 struct jpeg_decompress_struct cinfo
;
8132 struct my_jpeg_error_mgr mgr
;
8133 Lisp_Object file
, specified_file
;
8134 Lisp_Object specified_data
;
8135 FILE * volatile fp
= NULL
;
8137 int row_stride
, x
, y
;
8138 XImage
*ximg
= NULL
;
8140 unsigned long *colors
;
8142 struct gcpro gcpro1
;
8144 /* Open the JPEG file. */
8145 specified_file
= image_spec_value (img
->spec
, QCfile
, NULL
);
8146 specified_data
= image_spec_value (img
->spec
, QCdata
, NULL
);
8150 if (NILP (specified_data
))
8152 file
= x_find_image_file (specified_file
);
8153 if (!STRINGP (file
))
8155 image_error ("Cannot find image file `%s'", specified_file
, Qnil
);
8160 fp
= fopen (SDATA (file
), "r");
8163 image_error ("Cannot open `%s'", file
, Qnil
);
8169 /* Customize libjpeg's error handling to call my_error_exit when an
8170 error is detected. This function will perform a longjmp. */
8171 cinfo
.err
= jpeg_std_error (&mgr
.pub
);
8172 mgr
.pub
.error_exit
= my_error_exit
;
8174 if ((rc
= setjmp (mgr
.setjmp_buffer
)) != 0)
8178 /* Called from my_error_exit. Display a JPEG error. */
8179 char buffer
[JMSG_LENGTH_MAX
];
8180 cinfo
.err
->format_message ((j_common_ptr
) &cinfo
, buffer
);
8181 image_error ("Error reading JPEG image `%s': %s", img
->spec
,
8182 build_string (buffer
));
8185 /* Close the input file and destroy the JPEG object. */
8187 fclose ((FILE *) fp
);
8188 jpeg_destroy_decompress (&cinfo
);
8190 /* If we already have an XImage, free that. */
8191 x_destroy_x_image (ximg
);
8193 /* Free pixmap and colors. */
8194 x_clear_image (f
, img
);
8200 /* Create the JPEG decompression object. Let it read from fp.
8201 Read the JPEG image header. */
8202 jpeg_create_decompress (&cinfo
);
8204 if (NILP (specified_data
))
8205 jpeg_stdio_src (&cinfo
, (FILE *) fp
);
8207 jpeg_memory_src (&cinfo
, SDATA (specified_data
),
8208 SBYTES (specified_data
));
8210 jpeg_read_header (&cinfo
, TRUE
);
8212 /* Customize decompression so that color quantization will be used.
8213 Start decompression. */
8214 cinfo
.quantize_colors
= TRUE
;
8215 jpeg_start_decompress (&cinfo
);
8216 width
= img
->width
= cinfo
.output_width
;
8217 height
= img
->height
= cinfo
.output_height
;
8219 /* Create X image and pixmap. */
8220 if (!x_create_x_image_and_pixmap (f
, width
, height
, 0, &ximg
, &img
->pixmap
))
8221 longjmp (mgr
.setjmp_buffer
, 2);
8223 /* Allocate colors. When color quantization is used,
8224 cinfo.actual_number_of_colors has been set with the number of
8225 colors generated, and cinfo.colormap is a two-dimensional array
8226 of color indices in the range 0..cinfo.actual_number_of_colors.
8227 No more than 255 colors will be generated. */
8231 if (cinfo
.out_color_components
> 2)
8232 ir
= 0, ig
= 1, ib
= 2;
8233 else if (cinfo
.out_color_components
> 1)
8234 ir
= 0, ig
= 1, ib
= 0;
8236 ir
= 0, ig
= 0, ib
= 0;
8238 /* Use the color table mechanism because it handles colors that
8239 cannot be allocated nicely. Such colors will be replaced with
8240 a default color, and we don't have to care about which colors
8241 can be freed safely, and which can't. */
8242 init_color_table ();
8243 colors
= (unsigned long *) alloca (cinfo
.actual_number_of_colors
8246 for (i
= 0; i
< cinfo
.actual_number_of_colors
; ++i
)
8248 /* Multiply RGB values with 255 because X expects RGB values
8249 in the range 0..0xffff. */
8250 int r
= cinfo
.colormap
[ir
][i
] << 8;
8251 int g
= cinfo
.colormap
[ig
][i
] << 8;
8252 int b
= cinfo
.colormap
[ib
][i
] << 8;
8253 colors
[i
] = lookup_rgb_color (f
, r
, g
, b
);
8256 /* Remember those colors actually allocated. */
8257 img
->colors
= colors_in_color_table (&img
->ncolors
);
8258 free_color_table ();
8262 row_stride
= width
* cinfo
.output_components
;
8263 buffer
= cinfo
.mem
->alloc_sarray ((j_common_ptr
) &cinfo
, JPOOL_IMAGE
,
8265 for (y
= 0; y
< height
; ++y
)
8267 jpeg_read_scanlines (&cinfo
, buffer
, 1);
8268 for (x
= 0; x
< cinfo
.output_width
; ++x
)
8269 XPutPixel (ximg
, x
, y
, colors
[buffer
[0][x
]]);
8273 jpeg_finish_decompress (&cinfo
);
8274 jpeg_destroy_decompress (&cinfo
);
8276 fclose ((FILE *) fp
);
8278 /* Maybe fill in the background field while we have ximg handy. */
8279 if (NILP (image_spec_value (img
->spec
, QCbackground
, NULL
)))
8280 IMAGE_BACKGROUND (img
, f
, ximg
);
8282 /* Put the image into the pixmap. */
8283 x_put_x_image (f
, ximg
, img
->pixmap
, width
, height
);
8284 x_destroy_x_image (ximg
);
8289 #endif /* HAVE_JPEG */
8293 /***********************************************************************
8295 ***********************************************************************/
8301 static int tiff_image_p
P_ ((Lisp_Object object
));
8302 static int tiff_load
P_ ((struct frame
*f
, struct image
*img
));
8304 /* The symbol `tiff' identifying images of this type. */
8308 /* Indices of image specification fields in tiff_format, below. */
8310 enum tiff_keyword_index
8319 TIFF_HEURISTIC_MASK
,
8325 /* Vector of image_keyword structures describing the format
8326 of valid user-defined image specifications. */
8328 static struct image_keyword tiff_format
[TIFF_LAST
] =
8330 {":type", IMAGE_SYMBOL_VALUE
, 1},
8331 {":data", IMAGE_STRING_VALUE
, 0},
8332 {":file", IMAGE_STRING_VALUE
, 0},
8333 {":ascent", IMAGE_ASCENT_VALUE
, 0},
8334 {":margin", IMAGE_POSITIVE_INTEGER_VALUE_OR_PAIR
, 0},
8335 {":relief", IMAGE_INTEGER_VALUE
, 0},
8336 {":conversions", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
8337 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
8338 {":mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
8339 {":background", IMAGE_STRING_OR_NIL_VALUE
, 0}
8342 /* Structure describing the image type `tiff'. */
8344 static struct image_type tiff_type
=
8354 /* Return non-zero if OBJECT is a valid TIFF image specification. */
8357 tiff_image_p (object
)
8360 struct image_keyword fmt
[TIFF_LAST
];
8361 bcopy (tiff_format
, fmt
, sizeof fmt
);
8363 if (!parse_image_spec (object
, fmt
, TIFF_LAST
, Qtiff
))
8366 /* Must specify either the :data or :file keyword. */
8367 return fmt
[TIFF_FILE
].count
+ fmt
[TIFF_DATA
].count
== 1;
8371 /* Reading from a memory buffer for TIFF images Based on the PNG
8372 memory source, but we have to provide a lot of extra functions.
8375 We really only need to implement read and seek, but I am not
8376 convinced that the TIFF library is smart enough not to destroy
8377 itself if we only hand it the function pointers we need to
8382 unsigned char *bytes
;
8390 tiff_read_from_memory (data
, buf
, size
)
8395 tiff_memory_source
*src
= (tiff_memory_source
*) data
;
8397 if (size
> src
->len
- src
->index
)
8399 bcopy (src
->bytes
+ src
->index
, buf
, size
);
8406 tiff_write_from_memory (data
, buf
, size
)
8416 tiff_seek_in_memory (data
, off
, whence
)
8421 tiff_memory_source
*src
= (tiff_memory_source
*) data
;
8426 case SEEK_SET
: /* Go from beginning of source. */
8430 case SEEK_END
: /* Go from end of source. */
8431 idx
= src
->len
+ off
;
8434 case SEEK_CUR
: /* Go from current position. */
8435 idx
= src
->index
+ off
;
8438 default: /* Invalid `whence'. */
8442 if (idx
> src
->len
|| idx
< 0)
8451 tiff_close_memory (data
)
8460 tiff_mmap_memory (data
, pbase
, psize
)
8465 /* It is already _IN_ memory. */
8471 tiff_unmap_memory (data
, base
, size
)
8476 /* We don't need to do this. */
8481 tiff_size_of_memory (data
)
8484 return ((tiff_memory_source
*) data
)->len
;
8489 tiff_error_handler (title
, format
, ap
)
8490 const char *title
, *format
;
8496 len
= sprintf (buf
, "TIFF error: %s ", title
);
8497 vsprintf (buf
+ len
, format
, ap
);
8498 add_to_log (buf
, Qnil
, Qnil
);
8503 tiff_warning_handler (title
, format
, ap
)
8504 const char *title
, *format
;
8510 len
= sprintf (buf
, "TIFF warning: %s ", title
);
8511 vsprintf (buf
+ len
, format
, ap
);
8512 add_to_log (buf
, Qnil
, Qnil
);
8516 /* Load TIFF image IMG for use on frame F. Value is non-zero if
8524 Lisp_Object file
, specified_file
;
8525 Lisp_Object specified_data
;
8527 int width
, height
, x
, y
;
8531 struct gcpro gcpro1
;
8532 tiff_memory_source memsrc
;
8534 specified_file
= image_spec_value (img
->spec
, QCfile
, NULL
);
8535 specified_data
= image_spec_value (img
->spec
, QCdata
, NULL
);
8539 TIFFSetErrorHandler (tiff_error_handler
);
8540 TIFFSetWarningHandler (tiff_warning_handler
);
8542 if (NILP (specified_data
))
8544 /* Read from a file */
8545 file
= x_find_image_file (specified_file
);
8546 if (!STRINGP (file
))
8548 image_error ("Cannot find image file `%s'", file
, Qnil
);
8553 /* Try to open the image file. */
8554 tiff
= TIFFOpen (SDATA (file
), "r");
8557 image_error ("Cannot open `%s'", file
, Qnil
);
8564 /* Memory source! */
8565 memsrc
.bytes
= SDATA (specified_data
);
8566 memsrc
.len
= SBYTES (specified_data
);
8569 tiff
= TIFFClientOpen ("memory_source", "r", &memsrc
,
8570 (TIFFReadWriteProc
) tiff_read_from_memory
,
8571 (TIFFReadWriteProc
) tiff_write_from_memory
,
8572 tiff_seek_in_memory
,
8574 tiff_size_of_memory
,
8580 image_error ("Cannot open memory source for `%s'", img
->spec
, Qnil
);
8586 /* Get width and height of the image, and allocate a raster buffer
8587 of width x height 32-bit values. */
8588 TIFFGetField (tiff
, TIFFTAG_IMAGEWIDTH
, &width
);
8589 TIFFGetField (tiff
, TIFFTAG_IMAGELENGTH
, &height
);
8590 buf
= (uint32
*) xmalloc (width
* height
* sizeof *buf
);
8592 rc
= TIFFReadRGBAImage (tiff
, width
, height
, buf
, 0);
8596 image_error ("Error reading TIFF image `%s'", img
->spec
, Qnil
);
8602 /* Create the X image and pixmap. */
8603 if (!x_create_x_image_and_pixmap (f
, width
, height
, 0, &ximg
, &img
->pixmap
))
8610 /* Initialize the color table. */
8611 init_color_table ();
8613 /* Process the pixel raster. Origin is in the lower-left corner. */
8614 for (y
= 0; y
< height
; ++y
)
8616 uint32
*row
= buf
+ y
* width
;
8618 for (x
= 0; x
< width
; ++x
)
8620 uint32 abgr
= row
[x
];
8621 int r
= TIFFGetR (abgr
) << 8;
8622 int g
= TIFFGetG (abgr
) << 8;
8623 int b
= TIFFGetB (abgr
) << 8;
8624 XPutPixel (ximg
, x
, height
- 1 - y
, lookup_rgb_color (f
, r
, g
, b
));
8628 /* Remember the colors allocated for the image. Free the color table. */
8629 img
->colors
= colors_in_color_table (&img
->ncolors
);
8630 free_color_table ();
8633 img
->height
= height
;
8635 /* Maybe fill in the background field while we have ximg handy. */
8636 if (NILP (image_spec_value (img
->spec
, QCbackground
, NULL
)))
8637 IMAGE_BACKGROUND (img
, f
, ximg
);
8639 /* Put the image into the pixmap, then free the X image and its buffer. */
8640 x_put_x_image (f
, ximg
, img
->pixmap
, width
, height
);
8641 x_destroy_x_image (ximg
);
8648 #endif /* HAVE_TIFF != 0 */
8652 /***********************************************************************
8654 ***********************************************************************/
8658 #include <gif_lib.h>
8660 static int gif_image_p
P_ ((Lisp_Object object
));
8661 static int gif_load
P_ ((struct frame
*f
, struct image
*img
));
8663 /* The symbol `gif' identifying images of this type. */
8667 /* Indices of image specification fields in gif_format, below. */
8669 enum gif_keyword_index
8685 /* Vector of image_keyword structures describing the format
8686 of valid user-defined image specifications. */
8688 static struct image_keyword gif_format
[GIF_LAST
] =
8690 {":type", IMAGE_SYMBOL_VALUE
, 1},
8691 {":data", IMAGE_STRING_VALUE
, 0},
8692 {":file", IMAGE_STRING_VALUE
, 0},
8693 {":ascent", IMAGE_ASCENT_VALUE
, 0},
8694 {":margin", IMAGE_POSITIVE_INTEGER_VALUE_OR_PAIR
, 0},
8695 {":relief", IMAGE_INTEGER_VALUE
, 0},
8696 {":conversion", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
8697 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
8698 {":mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
8699 {":image", IMAGE_NON_NEGATIVE_INTEGER_VALUE
, 0},
8700 {":background", IMAGE_STRING_OR_NIL_VALUE
, 0}
8703 /* Structure describing the image type `gif'. */
8705 static struct image_type gif_type
=
8715 /* Return non-zero if OBJECT is a valid GIF image specification. */
8718 gif_image_p (object
)
8721 struct image_keyword fmt
[GIF_LAST
];
8722 bcopy (gif_format
, fmt
, sizeof fmt
);
8724 if (!parse_image_spec (object
, fmt
, GIF_LAST
, Qgif
))
8727 /* Must specify either the :data or :file keyword. */
8728 return fmt
[GIF_FILE
].count
+ fmt
[GIF_DATA
].count
== 1;
8732 /* Reading a GIF image from memory
8733 Based on the PNG memory stuff to a certain extent. */
8737 unsigned char *bytes
;
8744 /* Make the current memory source available to gif_read_from_memory.
8745 It's done this way because not all versions of libungif support
8746 a UserData field in the GifFileType structure. */
8747 static gif_memory_source
*current_gif_memory_src
;
8750 gif_read_from_memory (file
, buf
, len
)
8755 gif_memory_source
*src
= current_gif_memory_src
;
8757 if (len
> src
->len
- src
->index
)
8760 bcopy (src
->bytes
+ src
->index
, buf
, len
);
8766 /* Load GIF image IMG for use on frame F. Value is non-zero if
8774 Lisp_Object file
, specified_file
;
8775 Lisp_Object specified_data
;
8776 int rc
, width
, height
, x
, y
, i
;
8778 ColorMapObject
*gif_color_map
;
8779 unsigned long pixel_colors
[256];
8781 struct gcpro gcpro1
;
8783 int ino
, image_left
, image_top
, image_width
, image_height
;
8784 gif_memory_source memsrc
;
8785 unsigned char *raster
;
8787 specified_file
= image_spec_value (img
->spec
, QCfile
, NULL
);
8788 specified_data
= image_spec_value (img
->spec
, QCdata
, NULL
);
8792 if (NILP (specified_data
))
8794 file
= x_find_image_file (specified_file
);
8795 if (!STRINGP (file
))
8797 image_error ("Cannot find image file `%s'", specified_file
, Qnil
);
8802 /* Open the GIF file. */
8803 gif
= DGifOpenFileName (SDATA (file
));
8806 image_error ("Cannot open `%s'", file
, Qnil
);
8813 /* Read from memory! */
8814 current_gif_memory_src
= &memsrc
;
8815 memsrc
.bytes
= SDATA (specified_data
);
8816 memsrc
.len
= SBYTES (specified_data
);
8819 gif
= DGifOpen(&memsrc
, gif_read_from_memory
);
8822 image_error ("Cannot open memory source `%s'", img
->spec
, Qnil
);
8828 /* Read entire contents. */
8829 rc
= DGifSlurp (gif
);
8830 if (rc
== GIF_ERROR
)
8832 image_error ("Error reading `%s'", img
->spec
, Qnil
);
8833 DGifCloseFile (gif
);
8838 image
= image_spec_value (img
->spec
, QCindex
, NULL
);
8839 ino
= INTEGERP (image
) ? XFASTINT (image
) : 0;
8840 if (ino
>= gif
->ImageCount
)
8842 image_error ("Invalid image number `%s' in image `%s'",
8844 DGifCloseFile (gif
);
8849 width
= img
->width
= max (gif
->SWidth
, gif
->Image
.Left
+ gif
->Image
.Width
);
8850 height
= img
->height
= max (gif
->SHeight
, gif
->Image
.Top
+ gif
->Image
.Height
);
8852 /* Create the X image and pixmap. */
8853 if (!x_create_x_image_and_pixmap (f
, width
, height
, 0, &ximg
, &img
->pixmap
))
8855 DGifCloseFile (gif
);
8860 /* Allocate colors. */
8861 gif_color_map
= gif
->SavedImages
[ino
].ImageDesc
.ColorMap
;
8863 gif_color_map
= gif
->SColorMap
;
8864 init_color_table ();
8865 bzero (pixel_colors
, sizeof pixel_colors
);
8867 for (i
= 0; i
< gif_color_map
->ColorCount
; ++i
)
8869 int r
= gif_color_map
->Colors
[i
].Red
<< 8;
8870 int g
= gif_color_map
->Colors
[i
].Green
<< 8;
8871 int b
= gif_color_map
->Colors
[i
].Blue
<< 8;
8872 pixel_colors
[i
] = lookup_rgb_color (f
, r
, g
, b
);
8875 img
->colors
= colors_in_color_table (&img
->ncolors
);
8876 free_color_table ();
8878 /* Clear the part of the screen image that are not covered by
8879 the image from the GIF file. Full animated GIF support
8880 requires more than can be done here (see the gif89 spec,
8881 disposal methods). Let's simply assume that the part
8882 not covered by a sub-image is in the frame's background color. */
8883 image_top
= gif
->SavedImages
[ino
].ImageDesc
.Top
;
8884 image_left
= gif
->SavedImages
[ino
].ImageDesc
.Left
;
8885 image_width
= gif
->SavedImages
[ino
].ImageDesc
.Width
;
8886 image_height
= gif
->SavedImages
[ino
].ImageDesc
.Height
;
8888 for (y
= 0; y
< image_top
; ++y
)
8889 for (x
= 0; x
< width
; ++x
)
8890 XPutPixel (ximg
, x
, y
, FRAME_BACKGROUND_PIXEL (f
));
8892 for (y
= image_top
+ image_height
; y
< height
; ++y
)
8893 for (x
= 0; x
< width
; ++x
)
8894 XPutPixel (ximg
, x
, y
, FRAME_BACKGROUND_PIXEL (f
));
8896 for (y
= image_top
; y
< image_top
+ image_height
; ++y
)
8898 for (x
= 0; x
< image_left
; ++x
)
8899 XPutPixel (ximg
, x
, y
, FRAME_BACKGROUND_PIXEL (f
));
8900 for (x
= image_left
+ image_width
; x
< width
; ++x
)
8901 XPutPixel (ximg
, x
, y
, FRAME_BACKGROUND_PIXEL (f
));
8904 /* Read the GIF image into the X image. We use a local variable
8905 `raster' here because RasterBits below is a char *, and invites
8906 problems with bytes >= 0x80. */
8907 raster
= (unsigned char *) gif
->SavedImages
[ino
].RasterBits
;
8909 if (gif
->SavedImages
[ino
].ImageDesc
.Interlace
)
8911 static int interlace_start
[] = {0, 4, 2, 1};
8912 static int interlace_increment
[] = {8, 8, 4, 2};
8914 int row
= interlace_start
[0];
8918 for (y
= 0; y
< image_height
; y
++)
8920 if (row
>= image_height
)
8922 row
= interlace_start
[++pass
];
8923 while (row
>= image_height
)
8924 row
= interlace_start
[++pass
];
8927 for (x
= 0; x
< image_width
; x
++)
8929 int i
= raster
[(y
* image_width
) + x
];
8930 XPutPixel (ximg
, x
+ image_left
, row
+ image_top
,
8934 row
+= interlace_increment
[pass
];
8939 for (y
= 0; y
< image_height
; ++y
)
8940 for (x
= 0; x
< image_width
; ++x
)
8942 int i
= raster
[y
* image_width
+ x
];
8943 XPutPixel (ximg
, x
+ image_left
, y
+ image_top
, pixel_colors
[i
]);
8947 DGifCloseFile (gif
);
8949 /* Maybe fill in the background field while we have ximg handy. */
8950 if (NILP (image_spec_value (img
->spec
, QCbackground
, NULL
)))
8951 IMAGE_BACKGROUND (img
, f
, ximg
);
8953 /* Put the image into the pixmap, then free the X image and its buffer. */
8954 x_put_x_image (f
, ximg
, img
->pixmap
, width
, height
);
8955 x_destroy_x_image (ximg
);
8961 #endif /* HAVE_GIF != 0 */
8965 /***********************************************************************
8967 ***********************************************************************/
8969 static int gs_image_p
P_ ((Lisp_Object object
));
8970 static int gs_load
P_ ((struct frame
*f
, struct image
*img
));
8971 static void gs_clear_image
P_ ((struct frame
*f
, struct image
*img
));
8973 /* The symbol `postscript' identifying images of this type. */
8975 Lisp_Object Qpostscript
;
8977 /* Keyword symbols. */
8979 Lisp_Object QCloader
, QCbounding_box
, QCpt_width
, QCpt_height
;
8981 /* Indices of image specification fields in gs_format, below. */
8983 enum gs_keyword_index
9001 /* Vector of image_keyword structures describing the format
9002 of valid user-defined image specifications. */
9004 static struct image_keyword gs_format
[GS_LAST
] =
9006 {":type", IMAGE_SYMBOL_VALUE
, 1},
9007 {":pt-width", IMAGE_POSITIVE_INTEGER_VALUE
, 1},
9008 {":pt-height", IMAGE_POSITIVE_INTEGER_VALUE
, 1},
9009 {":file", IMAGE_STRING_VALUE
, 1},
9010 {":loader", IMAGE_FUNCTION_VALUE
, 0},
9011 {":bounding-box", IMAGE_DONT_CHECK_VALUE_TYPE
, 1},
9012 {":ascent", IMAGE_ASCENT_VALUE
, 0},
9013 {":margin", IMAGE_POSITIVE_INTEGER_VALUE_OR_PAIR
, 0},
9014 {":relief", IMAGE_INTEGER_VALUE
, 0},
9015 {":conversion", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
9016 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
9017 {":mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
9018 {":background", IMAGE_STRING_OR_NIL_VALUE
, 0}
9021 /* Structure describing the image type `ghostscript'. */
9023 static struct image_type gs_type
=
9033 /* Free X resources of Ghostscript image IMG which is used on frame F. */
9036 gs_clear_image (f
, img
)
9040 /* IMG->data.ptr_val may contain a recorded colormap. */
9041 xfree (img
->data
.ptr_val
);
9042 x_clear_image (f
, img
);
9046 /* Return non-zero if OBJECT is a valid Ghostscript image
9053 struct image_keyword fmt
[GS_LAST
];
9057 bcopy (gs_format
, fmt
, sizeof fmt
);
9059 if (!parse_image_spec (object
, fmt
, GS_LAST
, Qpostscript
))
9062 /* Bounding box must be a list or vector containing 4 integers. */
9063 tem
= fmt
[GS_BOUNDING_BOX
].value
;
9066 for (i
= 0; i
< 4; ++i
, tem
= XCDR (tem
))
9067 if (!CONSP (tem
) || !INTEGERP (XCAR (tem
)))
9072 else if (VECTORP (tem
))
9074 if (XVECTOR (tem
)->size
!= 4)
9076 for (i
= 0; i
< 4; ++i
)
9077 if (!INTEGERP (XVECTOR (tem
)->contents
[i
]))
9087 /* Load Ghostscript image IMG for use on frame F. Value is non-zero
9096 Lisp_Object window_and_pixmap_id
= Qnil
, loader
, pt_height
, pt_width
;
9097 struct gcpro gcpro1
, gcpro2
;
9099 double in_width
, in_height
;
9100 Lisp_Object pixel_colors
= Qnil
;
9102 /* Compute pixel size of pixmap needed from the given size in the
9103 image specification. Sizes in the specification are in pt. 1 pt
9104 = 1/72 in, xdpi and ydpi are stored in the frame's X display
9106 pt_width
= image_spec_value (img
->spec
, QCpt_width
, NULL
);
9107 in_width
= XFASTINT (pt_width
) / 72.0;
9108 img
->width
= in_width
* FRAME_X_DISPLAY_INFO (f
)->resx
;
9109 pt_height
= image_spec_value (img
->spec
, QCpt_height
, NULL
);
9110 in_height
= XFASTINT (pt_height
) / 72.0;
9111 img
->height
= in_height
* FRAME_X_DISPLAY_INFO (f
)->resy
;
9113 /* Create the pixmap. */
9114 xassert (img
->pixmap
== None
);
9115 img
->pixmap
= XCreatePixmap (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
9116 img
->width
, img
->height
,
9117 DefaultDepthOfScreen (FRAME_X_SCREEN (f
)));
9121 image_error ("Unable to create pixmap for `%s'", img
->spec
, Qnil
);
9125 /* Call the loader to fill the pixmap. It returns a process object
9126 if successful. We do not record_unwind_protect here because
9127 other places in redisplay like calling window scroll functions
9128 don't either. Let the Lisp loader use `unwind-protect' instead. */
9129 GCPRO2 (window_and_pixmap_id
, pixel_colors
);
9131 sprintf (buffer
, "%lu %lu",
9132 (unsigned long) FRAME_X_WINDOW (f
),
9133 (unsigned long) img
->pixmap
);
9134 window_and_pixmap_id
= build_string (buffer
);
9136 sprintf (buffer
, "%lu %lu",
9137 FRAME_FOREGROUND_PIXEL (f
),
9138 FRAME_BACKGROUND_PIXEL (f
));
9139 pixel_colors
= build_string (buffer
);
9141 XSETFRAME (frame
, f
);
9142 loader
= image_spec_value (img
->spec
, QCloader
, NULL
);
9144 loader
= intern ("gs-load-image");
9146 img
->data
.lisp_val
= call6 (loader
, frame
, img
->spec
,
9147 make_number (img
->width
),
9148 make_number (img
->height
),
9149 window_and_pixmap_id
,
9152 return PROCESSP (img
->data
.lisp_val
);
9156 /* Kill the Ghostscript process that was started to fill PIXMAP on
9157 frame F. Called from XTread_socket when receiving an event
9158 telling Emacs that Ghostscript has finished drawing. */
9161 x_kill_gs_process (pixmap
, f
)
9165 struct image_cache
*c
= FRAME_X_IMAGE_CACHE (f
);
9169 /* Find the image containing PIXMAP. */
9170 for (i
= 0; i
< c
->used
; ++i
)
9171 if (c
->images
[i
]->pixmap
== pixmap
)
9174 /* Should someone in between have cleared the image cache, for
9175 instance, give up. */
9179 /* Kill the GS process. We should have found PIXMAP in the image
9180 cache and its image should contain a process object. */
9182 xassert (PROCESSP (img
->data
.lisp_val
));
9183 Fkill_process (img
->data
.lisp_val
, Qnil
);
9184 img
->data
.lisp_val
= Qnil
;
9186 /* On displays with a mutable colormap, figure out the colors
9187 allocated for the image by looking at the pixels of an XImage for
9189 class = FRAME_X_VISUAL (f
)->class;
9190 if (class != StaticColor
&& class != StaticGray
&& class != TrueColor
)
9196 /* Try to get an XImage for img->pixmep. */
9197 ximg
= XGetImage (FRAME_X_DISPLAY (f
), img
->pixmap
,
9198 0, 0, img
->width
, img
->height
, ~0, ZPixmap
);
9203 /* Initialize the color table. */
9204 init_color_table ();
9206 /* For each pixel of the image, look its color up in the
9207 color table. After having done so, the color table will
9208 contain an entry for each color used by the image. */
9209 for (y
= 0; y
< img
->height
; ++y
)
9210 for (x
= 0; x
< img
->width
; ++x
)
9212 unsigned long pixel
= XGetPixel (ximg
, x
, y
);
9213 lookup_pixel_color (f
, pixel
);
9216 /* Record colors in the image. Free color table and XImage. */
9217 img
->colors
= colors_in_color_table (&img
->ncolors
);
9218 free_color_table ();
9219 XDestroyImage (ximg
);
9221 #if 0 /* This doesn't seem to be the case. If we free the colors
9222 here, we get a BadAccess later in x_clear_image when
9223 freeing the colors. */
9224 /* We have allocated colors once, but Ghostscript has also
9225 allocated colors on behalf of us. So, to get the
9226 reference counts right, free them once. */
9228 x_free_colors (f
, img
->colors
, img
->ncolors
);
9232 image_error ("Cannot get X image of `%s'; colors will not be freed",
9238 /* Now that we have the pixmap, compute mask and transform the
9239 image if requested. */
9241 postprocess_image (f
, img
);
9247 /***********************************************************************
9249 ***********************************************************************/
9251 DEFUN ("x-change-window-property", Fx_change_window_property
,
9252 Sx_change_window_property
, 2, 3, 0,
9253 doc
: /* Change window property PROP to VALUE on the X window of FRAME.
9254 PROP and VALUE must be strings. FRAME nil or omitted means use the
9255 selected frame. Value is VALUE. */)
9256 (prop
, value
, frame
)
9257 Lisp_Object frame
, prop
, value
;
9259 struct frame
*f
= check_x_frame (frame
);
9262 CHECK_STRING (prop
);
9263 CHECK_STRING (value
);
9266 prop_atom
= XInternAtom (FRAME_X_DISPLAY (f
), SDATA (prop
), False
);
9267 XChangeProperty (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
9268 prop_atom
, XA_STRING
, 8, PropModeReplace
,
9269 SDATA (value
), SCHARS (value
));
9271 /* Make sure the property is set when we return. */
9272 XFlush (FRAME_X_DISPLAY (f
));
9279 DEFUN ("x-delete-window-property", Fx_delete_window_property
,
9280 Sx_delete_window_property
, 1, 2, 0,
9281 doc
: /* Remove window property PROP from X window of FRAME.
9282 FRAME nil or omitted means use the selected frame. Value is PROP. */)
9284 Lisp_Object prop
, frame
;
9286 struct frame
*f
= check_x_frame (frame
);
9289 CHECK_STRING (prop
);
9291 prop_atom
= XInternAtom (FRAME_X_DISPLAY (f
), SDATA (prop
), False
);
9292 XDeleteProperty (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), prop_atom
);
9294 /* Make sure the property is removed when we return. */
9295 XFlush (FRAME_X_DISPLAY (f
));
9302 DEFUN ("x-window-property", Fx_window_property
, Sx_window_property
,
9304 doc
: /* Value is the value of window property PROP on FRAME.
9305 If FRAME is nil or omitted, use the selected frame. Value is nil
9306 if FRAME hasn't a property with name PROP or if PROP has no string
9309 Lisp_Object prop
, frame
;
9311 struct frame
*f
= check_x_frame (frame
);
9314 Lisp_Object prop_value
= Qnil
;
9315 char *tmp_data
= NULL
;
9318 unsigned long actual_size
, bytes_remaining
;
9320 CHECK_STRING (prop
);
9322 prop_atom
= XInternAtom (FRAME_X_DISPLAY (f
), SDATA (prop
), False
);
9323 rc
= XGetWindowProperty (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
9324 prop_atom
, 0, 0, False
, XA_STRING
,
9325 &actual_type
, &actual_format
, &actual_size
,
9326 &bytes_remaining
, (unsigned char **) &tmp_data
);
9329 int size
= bytes_remaining
;
9334 rc
= XGetWindowProperty (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
9335 prop_atom
, 0, bytes_remaining
,
9337 &actual_type
, &actual_format
,
9338 &actual_size
, &bytes_remaining
,
9339 (unsigned char **) &tmp_data
);
9340 if (rc
== Success
&& tmp_data
)
9341 prop_value
= make_string (tmp_data
, size
);
9352 /***********************************************************************
9354 ***********************************************************************/
9356 /* If non-null, an asynchronous timer that, when it expires, displays
9357 an hourglass cursor on all frames. */
9359 static struct atimer
*hourglass_atimer
;
9361 /* Non-zero means an hourglass cursor is currently shown. */
9363 static int hourglass_shown_p
;
9365 /* Number of seconds to wait before displaying an hourglass cursor. */
9367 static Lisp_Object Vhourglass_delay
;
9369 /* Default number of seconds to wait before displaying an hourglass
9372 #define DEFAULT_HOURGLASS_DELAY 1
9374 /* Function prototypes. */
9376 static void show_hourglass
P_ ((struct atimer
*));
9377 static void hide_hourglass
P_ ((void));
9380 /* Cancel a currently active hourglass timer, and start a new one. */
9386 int secs
, usecs
= 0;
9388 cancel_hourglass ();
9390 if (INTEGERP (Vhourglass_delay
)
9391 && XINT (Vhourglass_delay
) > 0)
9392 secs
= XFASTINT (Vhourglass_delay
);
9393 else if (FLOATP (Vhourglass_delay
)
9394 && XFLOAT_DATA (Vhourglass_delay
) > 0)
9397 tem
= Ftruncate (Vhourglass_delay
, Qnil
);
9398 secs
= XFASTINT (tem
);
9399 usecs
= (XFLOAT_DATA (Vhourglass_delay
) - secs
) * 1000000;
9402 secs
= DEFAULT_HOURGLASS_DELAY
;
9404 EMACS_SET_SECS_USECS (delay
, secs
, usecs
);
9405 hourglass_atimer
= start_atimer (ATIMER_RELATIVE
, delay
,
9406 show_hourglass
, NULL
);
9410 /* Cancel the hourglass cursor timer if active, hide a busy cursor if
9416 if (hourglass_atimer
)
9418 cancel_atimer (hourglass_atimer
);
9419 hourglass_atimer
= NULL
;
9422 if (hourglass_shown_p
)
9427 /* Timer function of hourglass_atimer. TIMER is equal to
9430 Display an hourglass pointer on all frames by mapping the frames'
9431 hourglass_window. Set the hourglass_p flag in the frames'
9432 output_data.x structure to indicate that an hourglass cursor is
9433 shown on the frames. */
9436 show_hourglass (timer
)
9437 struct atimer
*timer
;
9439 /* The timer implementation will cancel this timer automatically
9440 after this function has run. Set hourglass_atimer to null
9441 so that we know the timer doesn't have to be canceled. */
9442 hourglass_atimer
= NULL
;
9444 if (!hourglass_shown_p
)
9446 Lisp_Object rest
, frame
;
9450 FOR_EACH_FRAME (rest
, frame
)
9452 struct frame
*f
= XFRAME (frame
);
9454 if (FRAME_LIVE_P (f
) && FRAME_X_P (f
) && FRAME_X_DISPLAY (f
))
9456 Display
*dpy
= FRAME_X_DISPLAY (f
);
9458 #ifdef USE_X_TOOLKIT
9459 if (f
->output_data
.x
->widget
)
9461 if (FRAME_OUTER_WINDOW (f
))
9464 f
->output_data
.x
->hourglass_p
= 1;
9466 if (!f
->output_data
.x
->hourglass_window
)
9468 unsigned long mask
= CWCursor
;
9469 XSetWindowAttributes attrs
;
9471 attrs
.cursor
= f
->output_data
.x
->hourglass_cursor
;
9473 f
->output_data
.x
->hourglass_window
9474 = XCreateWindow (dpy
, FRAME_OUTER_WINDOW (f
),
9475 0, 0, 32000, 32000, 0, 0,
9481 XMapRaised (dpy
, f
->output_data
.x
->hourglass_window
);
9487 hourglass_shown_p
= 1;
9493 /* Hide the hourglass pointer on all frames, if it is currently
9499 if (hourglass_shown_p
)
9501 Lisp_Object rest
, frame
;
9504 FOR_EACH_FRAME (rest
, frame
)
9506 struct frame
*f
= XFRAME (frame
);
9509 /* Watch out for newly created frames. */
9510 && f
->output_data
.x
->hourglass_window
)
9512 XUnmapWindow (FRAME_X_DISPLAY (f
),
9513 f
->output_data
.x
->hourglass_window
);
9514 /* Sync here because XTread_socket looks at the
9515 hourglass_p flag that is reset to zero below. */
9516 XSync (FRAME_X_DISPLAY (f
), False
);
9517 f
->output_data
.x
->hourglass_p
= 0;
9521 hourglass_shown_p
= 0;
9528 /***********************************************************************
9530 ***********************************************************************/
9532 static Lisp_Object x_create_tip_frame
P_ ((struct x_display_info
*,
9533 Lisp_Object
, Lisp_Object
));
9534 static void compute_tip_xy
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
,
9535 Lisp_Object
, int, int, int *, int *));
9537 /* The frame of a currently visible tooltip. */
9539 Lisp_Object tip_frame
;
9541 /* If non-nil, a timer started that hides the last tooltip when it
9544 Lisp_Object tip_timer
;
9547 /* If non-nil, a vector of 3 elements containing the last args
9548 with which x-show-tip was called. See there. */
9550 Lisp_Object last_show_tip_args
;
9552 /* Maximum size for tooltips; a cons (COLUMNS . ROWS). */
9554 Lisp_Object Vx_max_tooltip_size
;
9558 unwind_create_tip_frame (frame
)
9561 Lisp_Object deleted
;
9563 deleted
= unwind_create_frame (frame
);
9564 if (EQ (deleted
, Qt
))
9574 /* Create a frame for a tooltip on the display described by DPYINFO.
9575 PARMS is a list of frame parameters. TEXT is the string to
9576 display in the tip frame. Value is the frame.
9578 Note that functions called here, esp. x_default_parameter can
9579 signal errors, for instance when a specified color name is
9580 undefined. We have to make sure that we're in a consistent state
9581 when this happens. */
9584 x_create_tip_frame (dpyinfo
, parms
, text
)
9585 struct x_display_info
*dpyinfo
;
9586 Lisp_Object parms
, text
;
9589 Lisp_Object frame
, tem
;
9591 long window_prompting
= 0;
9593 int count
= SPECPDL_INDEX ();
9594 struct gcpro gcpro1
, gcpro2
, gcpro3
;
9596 int face_change_count_before
= face_change_count
;
9598 struct buffer
*old_buffer
;
9602 /* Use this general default value to start with until we know if
9603 this frame has a specified name. */
9604 Vx_resource_name
= Vinvocation_name
;
9607 kb
= dpyinfo
->kboard
;
9609 kb
= &the_only_kboard
;
9612 /* Get the name of the frame to use for resource lookup. */
9613 name
= x_get_arg (dpyinfo
, parms
, Qname
, "name", "Name", RES_TYPE_STRING
);
9615 && !EQ (name
, Qunbound
)
9617 error ("Invalid frame name--not a string or nil");
9618 Vx_resource_name
= name
;
9621 GCPRO3 (parms
, name
, frame
);
9623 XSETFRAME (frame
, f
);
9625 buffer
= Fget_buffer_create (build_string (" *tip*"));
9626 Fset_window_buffer (FRAME_ROOT_WINDOW (f
), buffer
);
9627 old_buffer
= current_buffer
;
9628 set_buffer_internal_1 (XBUFFER (buffer
));
9629 current_buffer
->truncate_lines
= Qnil
;
9632 set_buffer_internal_1 (old_buffer
);
9634 FRAME_CAN_HAVE_SCROLL_BARS (f
) = 0;
9635 record_unwind_protect (unwind_create_tip_frame
, frame
);
9637 /* By setting the output method, we're essentially saying that
9638 the frame is live, as per FRAME_LIVE_P. If we get a signal
9639 from this point on, x_destroy_window might screw up reference
9641 f
->output_method
= output_x_window
;
9642 f
->output_data
.x
= (struct x_output
*) xmalloc (sizeof (struct x_output
));
9643 bzero (f
->output_data
.x
, sizeof (struct x_output
));
9644 f
->output_data
.x
->icon_bitmap
= -1;
9645 f
->output_data
.x
->fontset
= -1;
9646 f
->output_data
.x
->scroll_bar_foreground_pixel
= -1;
9647 f
->output_data
.x
->scroll_bar_background_pixel
= -1;
9648 #ifdef USE_TOOLKIT_SCROLL_BARS
9649 f
->output_data
.x
->scroll_bar_top_shadow_pixel
= -1;
9650 f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
= -1;
9651 #endif /* USE_TOOLKIT_SCROLL_BARS */
9652 f
->icon_name
= Qnil
;
9653 FRAME_X_DISPLAY_INFO (f
) = dpyinfo
;
9655 image_cache_refcount
= FRAME_X_IMAGE_CACHE (f
)->refcount
;
9656 dpyinfo_refcount
= dpyinfo
->reference_count
;
9657 #endif /* GLYPH_DEBUG */
9659 FRAME_KBOARD (f
) = kb
;
9661 f
->output_data
.x
->parent_desc
= FRAME_X_DISPLAY_INFO (f
)->root_window
;
9662 f
->output_data
.x
->explicit_parent
= 0;
9664 /* These colors will be set anyway later, but it's important
9665 to get the color reference counts right, so initialize them! */
9668 struct gcpro gcpro1
;
9670 black
= build_string ("black");
9672 f
->output_data
.x
->foreground_pixel
9673 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
9674 f
->output_data
.x
->background_pixel
9675 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
9676 f
->output_data
.x
->cursor_pixel
9677 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
9678 f
->output_data
.x
->cursor_foreground_pixel
9679 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
9680 f
->output_data
.x
->border_pixel
9681 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
9682 f
->output_data
.x
->mouse_pixel
9683 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
9687 /* Set the name; the functions to which we pass f expect the name to
9689 if (EQ (name
, Qunbound
) || NILP (name
))
9691 f
->name
= build_string (dpyinfo
->x_id_name
);
9692 f
->explicit_name
= 0;
9697 f
->explicit_name
= 1;
9698 /* use the frame's title when getting resources for this frame. */
9699 specbind (Qx_resource_name
, name
);
9702 /* Extract the window parameters from the supplied values that are
9703 needed to determine window geometry. */
9707 font
= x_get_arg (dpyinfo
, parms
, Qfont
, "font", "Font", RES_TYPE_STRING
);
9710 /* First, try whatever font the caller has specified. */
9713 tem
= Fquery_fontset (font
, Qnil
);
9715 font
= x_new_fontset (f
, SDATA (tem
));
9717 font
= x_new_font (f
, SDATA (font
));
9720 /* Try out a font which we hope has bold and italic variations. */
9721 if (!STRINGP (font
))
9722 font
= x_new_font (f
, "-adobe-courier-medium-r-*-*-*-120-*-*-*-*-iso8859-1");
9723 if (!STRINGP (font
))
9724 font
= x_new_font (f
, "-misc-fixed-medium-r-normal-*-*-140-*-*-c-*-iso8859-1");
9725 if (! STRINGP (font
))
9726 font
= x_new_font (f
, "-*-*-medium-r-normal-*-*-140-*-*-c-*-iso8859-1");
9727 if (! STRINGP (font
))
9728 /* This was formerly the first thing tried, but it finds too many fonts
9729 and takes too long. */
9730 font
= x_new_font (f
, "-*-*-medium-r-*-*-*-*-*-*-c-*-iso8859-1");
9731 /* If those didn't work, look for something which will at least work. */
9732 if (! STRINGP (font
))
9733 font
= x_new_font (f
, "-*-fixed-*-*-*-*-*-140-*-*-c-*-iso8859-1");
9735 if (! STRINGP (font
))
9736 font
= build_string ("fixed");
9738 x_default_parameter (f
, parms
, Qfont
, font
,
9739 "font", "Font", RES_TYPE_STRING
);
9742 x_default_parameter (f
, parms
, Qborder_width
, make_number (2),
9743 "borderWidth", "BorderWidth", RES_TYPE_NUMBER
);
9745 /* This defaults to 2 in order to match xterm. We recognize either
9746 internalBorderWidth or internalBorder (which is what xterm calls
9748 if (NILP (Fassq (Qinternal_border_width
, parms
)))
9752 value
= x_get_arg (dpyinfo
, parms
, Qinternal_border_width
,
9753 "internalBorder", "internalBorder", RES_TYPE_NUMBER
);
9754 if (! EQ (value
, Qunbound
))
9755 parms
= Fcons (Fcons (Qinternal_border_width
, value
),
9759 x_default_parameter (f
, parms
, Qinternal_border_width
, make_number (1),
9760 "internalBorderWidth", "internalBorderWidth",
9763 /* Also do the stuff which must be set before the window exists. */
9764 x_default_parameter (f
, parms
, Qforeground_color
, build_string ("black"),
9765 "foreground", "Foreground", RES_TYPE_STRING
);
9766 x_default_parameter (f
, parms
, Qbackground_color
, build_string ("white"),
9767 "background", "Background", RES_TYPE_STRING
);
9768 x_default_parameter (f
, parms
, Qmouse_color
, build_string ("black"),
9769 "pointerColor", "Foreground", RES_TYPE_STRING
);
9770 x_default_parameter (f
, parms
, Qcursor_color
, build_string ("black"),
9771 "cursorColor", "Foreground", RES_TYPE_STRING
);
9772 x_default_parameter (f
, parms
, Qborder_color
, build_string ("black"),
9773 "borderColor", "BorderColor", RES_TYPE_STRING
);
9775 /* Init faces before x_default_parameter is called for scroll-bar
9776 parameters because that function calls x_set_scroll_bar_width,
9777 which calls change_frame_size, which calls Fset_window_buffer,
9778 which runs hooks, which call Fvertical_motion. At the end, we
9779 end up in init_iterator with a null face cache, which should not
9781 init_frame_faces (f
);
9783 f
->output_data
.x
->parent_desc
= FRAME_X_DISPLAY_INFO (f
)->root_window
;
9785 window_prompting
= x_figure_window_size (f
, parms
, 0);
9788 XSetWindowAttributes attrs
;
9792 mask
= CWBackPixel
| CWOverrideRedirect
| CWEventMask
;
9793 if (DoesSaveUnders (dpyinfo
->screen
))
9794 mask
|= CWSaveUnder
;
9796 /* Window managers look at the override-redirect flag to determine
9797 whether or net to give windows a decoration (Xlib spec, chapter
9799 attrs
.override_redirect
= True
;
9800 attrs
.save_under
= True
;
9801 attrs
.background_pixel
= FRAME_BACKGROUND_PIXEL (f
);
9802 /* Arrange for getting MapNotify and UnmapNotify events. */
9803 attrs
.event_mask
= StructureNotifyMask
;
9805 = FRAME_X_WINDOW (f
)
9806 = XCreateWindow (FRAME_X_DISPLAY (f
),
9807 FRAME_X_DISPLAY_INFO (f
)->root_window
,
9808 /* x, y, width, height */
9812 CopyFromParent
, InputOutput
, CopyFromParent
,
9819 x_default_parameter (f
, parms
, Qauto_raise
, Qnil
,
9820 "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
9821 x_default_parameter (f
, parms
, Qauto_lower
, Qnil
,
9822 "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
9823 x_default_parameter (f
, parms
, Qcursor_type
, Qbox
,
9824 "cursorType", "CursorType", RES_TYPE_SYMBOL
);
9826 /* Dimensions, especially f->height, must be done via change_frame_size.
9827 Change will not be effected unless different from the current
9832 SET_FRAME_WIDTH (f
, 0);
9833 change_frame_size (f
, height
, width
, 1, 0, 0);
9835 /* Add `tooltip' frame parameter's default value. */
9836 if (NILP (Fframe_parameter (frame
, intern ("tooltip"))))
9837 Fmodify_frame_parameters (frame
, Fcons (Fcons (intern ("tooltip"), Qt
),
9840 /* Set up faces after all frame parameters are known. This call
9841 also merges in face attributes specified for new frames.
9843 Frame parameters may be changed if .Xdefaults contains
9844 specifications for the default font. For example, if there is an
9845 `Emacs.default.attributeBackground: pink', the `background-color'
9846 attribute of the frame get's set, which let's the internal border
9847 of the tooltip frame appear in pink. Prevent this. */
9849 Lisp_Object bg
= Fframe_parameter (frame
, Qbackground_color
);
9851 /* Set tip_frame here, so that */
9853 call1 (Qface_set_after_frame_default
, frame
);
9855 if (!EQ (bg
, Fframe_parameter (frame
, Qbackground_color
)))
9856 Fmodify_frame_parameters (frame
, Fcons (Fcons (Qbackground_color
, bg
),
9864 /* It is now ok to make the frame official even if we get an error
9865 below. And the frame needs to be on Vframe_list or making it
9866 visible won't work. */
9867 Vframe_list
= Fcons (frame
, Vframe_list
);
9869 /* Now that the frame is official, it counts as a reference to
9871 FRAME_X_DISPLAY_INFO (f
)->reference_count
++;
9873 /* Setting attributes of faces of the tooltip frame from resources
9874 and similar will increment face_change_count, which leads to the
9875 clearing of all current matrices. Since this isn't necessary
9876 here, avoid it by resetting face_change_count to the value it
9877 had before we created the tip frame. */
9878 face_change_count
= face_change_count_before
;
9880 /* Discard the unwind_protect. */
9881 return unbind_to (count
, frame
);
9885 /* Compute where to display tip frame F. PARMS is the list of frame
9886 parameters for F. DX and DY are specified offsets from the current
9887 location of the mouse. WIDTH and HEIGHT are the width and height
9888 of the tooltip. Return coordinates relative to the root window of
9889 the display in *ROOT_X, and *ROOT_Y. */
9892 compute_tip_xy (f
, parms
, dx
, dy
, width
, height
, root_x
, root_y
)
9894 Lisp_Object parms
, dx
, dy
;
9896 int *root_x
, *root_y
;
9898 Lisp_Object left
, top
;
9903 /* User-specified position? */
9904 left
= Fcdr (Fassq (Qleft
, parms
));
9905 top
= Fcdr (Fassq (Qtop
, parms
));
9907 /* Move the tooltip window where the mouse pointer is. Resize and
9909 if (!INTEGERP (left
) || !INTEGERP (top
))
9912 XQueryPointer (FRAME_X_DISPLAY (f
), FRAME_X_DISPLAY_INFO (f
)->root_window
,
9913 &root
, &child
, root_x
, root_y
, &win_x
, &win_y
, &pmask
);
9918 *root_y
= XINT (top
);
9919 else if (*root_y
+ XINT (dy
) - height
< 0)
9920 *root_y
-= XINT (dy
);
9924 *root_y
+= XINT (dy
);
9927 if (INTEGERP (left
))
9928 *root_x
= XINT (left
);
9929 else if (*root_x
+ XINT (dx
) + width
<= FRAME_X_DISPLAY_INFO (f
)->width
)
9930 /* It fits to the right of the pointer. */
9931 *root_x
+= XINT (dx
);
9932 else if (width
+ XINT (dx
) <= *root_x
)
9933 /* It fits to the left of the pointer. */
9934 *root_x
-= width
+ XINT (dx
);
9936 /* Put it left-justified on the screen--it ought to fit that way. */
9941 DEFUN ("x-show-tip", Fx_show_tip
, Sx_show_tip
, 1, 6, 0,
9942 doc
: /* Show STRING in a "tooltip" window on frame FRAME.
9943 A tooltip window is a small X window displaying a string.
9945 FRAME nil or omitted means use the selected frame.
9947 PARMS is an optional list of frame parameters which can be used to
9948 change the tooltip's appearance.
9950 Automatically hide the tooltip after TIMEOUT seconds. TIMEOUT nil
9951 means use the default timeout of 5 seconds.
9953 If the list of frame parameters PARAMS contains a `left' parameters,
9954 the tooltip is displayed at that x-position. Otherwise it is
9955 displayed at the mouse position, with offset DX added (default is 5 if
9956 DX isn't specified). Likewise for the y-position; if a `top' frame
9957 parameter is specified, it determines the y-position of the tooltip
9958 window, otherwise it is displayed at the mouse position, with offset
9959 DY added (default is -10).
9961 A tooltip's maximum size is specified by `x-max-tooltip-size'.
9962 Text larger than the specified size is clipped. */)
9963 (string
, frame
, parms
, timeout
, dx
, dy
)
9964 Lisp_Object string
, frame
, parms
, timeout
, dx
, dy
;
9969 struct buffer
*old_buffer
;
9970 struct text_pos pos
;
9971 int i
, width
, height
;
9972 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
9973 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
9974 int count
= SPECPDL_INDEX ();
9976 specbind (Qinhibit_redisplay
, Qt
);
9978 GCPRO4 (string
, parms
, frame
, timeout
);
9980 CHECK_STRING (string
);
9981 f
= check_x_frame (frame
);
9983 timeout
= make_number (5);
9985 CHECK_NATNUM (timeout
);
9988 dx
= make_number (5);
9993 dy
= make_number (-10);
9997 if (NILP (last_show_tip_args
))
9998 last_show_tip_args
= Fmake_vector (make_number (3), Qnil
);
10000 if (!NILP (tip_frame
))
10002 Lisp_Object last_string
= AREF (last_show_tip_args
, 0);
10003 Lisp_Object last_frame
= AREF (last_show_tip_args
, 1);
10004 Lisp_Object last_parms
= AREF (last_show_tip_args
, 2);
10006 if (EQ (frame
, last_frame
)
10007 && !NILP (Fequal (last_string
, string
))
10008 && !NILP (Fequal (last_parms
, parms
)))
10010 struct frame
*f
= XFRAME (tip_frame
);
10012 /* Only DX and DY have changed. */
10013 if (!NILP (tip_timer
))
10015 Lisp_Object timer
= tip_timer
;
10017 call1 (Qcancel_timer
, timer
);
10021 compute_tip_xy (f
, parms
, dx
, dy
, PIXEL_WIDTH (f
),
10022 PIXEL_HEIGHT (f
), &root_x
, &root_y
);
10023 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
10030 /* Hide a previous tip, if any. */
10033 ASET (last_show_tip_args
, 0, string
);
10034 ASET (last_show_tip_args
, 1, frame
);
10035 ASET (last_show_tip_args
, 2, parms
);
10037 /* Add default values to frame parameters. */
10038 if (NILP (Fassq (Qname
, parms
)))
10039 parms
= Fcons (Fcons (Qname
, build_string ("tooltip")), parms
);
10040 if (NILP (Fassq (Qinternal_border_width
, parms
)))
10041 parms
= Fcons (Fcons (Qinternal_border_width
, make_number (3)), parms
);
10042 if (NILP (Fassq (Qborder_width
, parms
)))
10043 parms
= Fcons (Fcons (Qborder_width
, make_number (1)), parms
);
10044 if (NILP (Fassq (Qborder_color
, parms
)))
10045 parms
= Fcons (Fcons (Qborder_color
, build_string ("lightyellow")), parms
);
10046 if (NILP (Fassq (Qbackground_color
, parms
)))
10047 parms
= Fcons (Fcons (Qbackground_color
, build_string ("lightyellow")),
10050 /* Create a frame for the tooltip, and record it in the global
10051 variable tip_frame. */
10052 frame
= x_create_tip_frame (FRAME_X_DISPLAY_INFO (f
), parms
, string
);
10053 f
= XFRAME (frame
);
10055 /* Set up the frame's root window. */
10056 w
= XWINDOW (FRAME_ROOT_WINDOW (f
));
10057 w
->left
= w
->top
= make_number (0);
10059 if (CONSP (Vx_max_tooltip_size
)
10060 && INTEGERP (XCAR (Vx_max_tooltip_size
))
10061 && XINT (XCAR (Vx_max_tooltip_size
)) > 0
10062 && INTEGERP (XCDR (Vx_max_tooltip_size
))
10063 && XINT (XCDR (Vx_max_tooltip_size
)) > 0)
10065 w
->width
= XCAR (Vx_max_tooltip_size
);
10066 w
->height
= XCDR (Vx_max_tooltip_size
);
10070 w
->width
= make_number (80);
10071 w
->height
= make_number (40);
10074 f
->window_width
= XINT (w
->width
);
10076 w
->pseudo_window_p
= 1;
10078 /* Display the tooltip text in a temporary buffer. */
10079 old_buffer
= current_buffer
;
10080 set_buffer_internal_1 (XBUFFER (XWINDOW (FRAME_ROOT_WINDOW (f
))->buffer
));
10081 current_buffer
->truncate_lines
= Qnil
;
10082 clear_glyph_matrix (w
->desired_matrix
);
10083 clear_glyph_matrix (w
->current_matrix
);
10084 SET_TEXT_POS (pos
, BEGV
, BEGV_BYTE
);
10085 try_window (FRAME_ROOT_WINDOW (f
), pos
);
10087 /* Compute width and height of the tooltip. */
10088 width
= height
= 0;
10089 for (i
= 0; i
< w
->desired_matrix
->nrows
; ++i
)
10091 struct glyph_row
*row
= &w
->desired_matrix
->rows
[i
];
10092 struct glyph
*last
;
10095 /* Stop at the first empty row at the end. */
10096 if (!row
->enabled_p
|| !row
->displays_text_p
)
10099 /* Let the row go over the full width of the frame. */
10100 row
->full_width_p
= 1;
10102 /* There's a glyph at the end of rows that is used to place
10103 the cursor there. Don't include the width of this glyph. */
10104 if (row
->used
[TEXT_AREA
])
10106 last
= &row
->glyphs
[TEXT_AREA
][row
->used
[TEXT_AREA
] - 1];
10107 row_width
= row
->pixel_width
- last
->pixel_width
;
10110 row_width
= row
->pixel_width
;
10112 height
+= row
->height
;
10113 width
= max (width
, row_width
);
10116 /* Add the frame's internal border to the width and height the X
10117 window should have. */
10118 height
+= 2 * FRAME_INTERNAL_BORDER_WIDTH (f
);
10119 width
+= 2 * FRAME_INTERNAL_BORDER_WIDTH (f
);
10121 /* Move the tooltip window where the mouse pointer is. Resize and
10123 compute_tip_xy (f
, parms
, dx
, dy
, width
, height
, &root_x
, &root_y
);
10126 XMoveResizeWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
10127 root_x
, root_y
, width
, height
);
10128 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
10131 /* Draw into the window. */
10132 w
->must_be_updated_p
= 1;
10133 update_single_window (w
, 1);
10135 /* Restore original current buffer. */
10136 set_buffer_internal_1 (old_buffer
);
10137 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
10140 /* Let the tip disappear after timeout seconds. */
10141 tip_timer
= call3 (intern ("run-at-time"), timeout
, Qnil
,
10142 intern ("x-hide-tip"));
10145 return unbind_to (count
, Qnil
);
10149 DEFUN ("x-hide-tip", Fx_hide_tip
, Sx_hide_tip
, 0, 0, 0,
10150 doc
: /* Hide the current tooltip window, if there is any.
10151 Value is t if tooltip was open, nil otherwise. */)
10155 Lisp_Object deleted
, frame
, timer
;
10156 struct gcpro gcpro1
, gcpro2
;
10158 /* Return quickly if nothing to do. */
10159 if (NILP (tip_timer
) && NILP (tip_frame
))
10164 GCPRO2 (frame
, timer
);
10165 tip_frame
= tip_timer
= deleted
= Qnil
;
10167 count
= SPECPDL_INDEX ();
10168 specbind (Qinhibit_redisplay
, Qt
);
10169 specbind (Qinhibit_quit
, Qt
);
10172 call1 (Qcancel_timer
, timer
);
10174 if (FRAMEP (frame
))
10176 Fdelete_frame (frame
, Qnil
);
10180 /* Bloodcurdling hack alert: The Lucid menu bar widget's
10181 redisplay procedure is not called when a tip frame over menu
10182 items is unmapped. Redisplay the menu manually... */
10184 struct frame
*f
= SELECTED_FRAME ();
10185 Widget w
= f
->output_data
.x
->menubar_widget
;
10186 extern void xlwmenu_redisplay
P_ ((Widget
));
10188 if (!DoesSaveUnders (FRAME_X_DISPLAY_INFO (f
)->screen
)
10192 xlwmenu_redisplay (w
);
10196 #endif /* USE_LUCID */
10200 return unbind_to (count
, deleted
);
10205 /***********************************************************************
10206 File selection dialog
10207 ***********************************************************************/
10211 /* Callback for "OK" and "Cancel" on file selection dialog. */
10214 file_dialog_cb (widget
, client_data
, call_data
)
10216 XtPointer call_data
, client_data
;
10218 int *result
= (int *) client_data
;
10219 XmAnyCallbackStruct
*cb
= (XmAnyCallbackStruct
*) call_data
;
10220 *result
= cb
->reason
;
10224 /* Callback for unmapping a file selection dialog. This is used to
10225 capture the case where a dialog is closed via a window manager's
10226 closer button, for example. Using a XmNdestroyCallback didn't work
10230 file_dialog_unmap_cb (widget
, client_data
, call_data
)
10232 XtPointer call_data
, client_data
;
10234 int *result
= (int *) client_data
;
10235 *result
= XmCR_CANCEL
;
10239 DEFUN ("x-file-dialog", Fx_file_dialog
, Sx_file_dialog
, 2, 4, 0,
10240 doc
: /* Read file name, prompting with PROMPT in directory DIR.
10241 Use a file selection dialog.
10242 Select DEFAULT-FILENAME in the dialog's file selection box, if
10243 specified. Don't let the user enter a file name in the file
10244 selection dialog's entry field, if MUSTMATCH is non-nil. */)
10245 (prompt
, dir
, default_filename
, mustmatch
)
10246 Lisp_Object prompt
, dir
, default_filename
, mustmatch
;
10249 struct frame
*f
= SELECTED_FRAME ();
10250 Lisp_Object file
= Qnil
;
10251 Widget dialog
, text
, list
, help
;
10254 extern XtAppContext Xt_app_con
;
10255 XmString dir_xmstring
, pattern_xmstring
;
10256 int count
= SPECPDL_INDEX ();
10257 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
, gcpro5
;
10259 GCPRO5 (prompt
, dir
, default_filename
, mustmatch
, file
);
10260 CHECK_STRING (prompt
);
10261 CHECK_STRING (dir
);
10263 /* Prevent redisplay. */
10264 specbind (Qinhibit_redisplay
, Qt
);
10268 /* Create the dialog with PROMPT as title, using DIR as initial
10269 directory and using "*" as pattern. */
10270 dir
= Fexpand_file_name (dir
, Qnil
);
10271 dir_xmstring
= XmStringCreateLocalized (SDATA (dir
));
10272 pattern_xmstring
= XmStringCreateLocalized ("*");
10274 XtSetArg (al
[ac
], XmNtitle
, SDATA (prompt
)); ++ac
;
10275 XtSetArg (al
[ac
], XmNdirectory
, dir_xmstring
); ++ac
;
10276 XtSetArg (al
[ac
], XmNpattern
, pattern_xmstring
); ++ac
;
10277 XtSetArg (al
[ac
], XmNresizePolicy
, XmRESIZE_GROW
); ++ac
;
10278 XtSetArg (al
[ac
], XmNdialogStyle
, XmDIALOG_APPLICATION_MODAL
); ++ac
;
10279 dialog
= XmCreateFileSelectionDialog (f
->output_data
.x
->widget
,
10281 XmStringFree (dir_xmstring
);
10282 XmStringFree (pattern_xmstring
);
10284 /* Add callbacks for OK and Cancel. */
10285 XtAddCallback (dialog
, XmNokCallback
, file_dialog_cb
,
10286 (XtPointer
) &result
);
10287 XtAddCallback (dialog
, XmNcancelCallback
, file_dialog_cb
,
10288 (XtPointer
) &result
);
10289 XtAddCallback (dialog
, XmNunmapCallback
, file_dialog_unmap_cb
,
10290 (XtPointer
) &result
);
10292 /* Disable the help button since we can't display help. */
10293 help
= XmFileSelectionBoxGetChild (dialog
, XmDIALOG_HELP_BUTTON
);
10294 XtSetSensitive (help
, False
);
10296 /* Mark OK button as default. */
10297 XtVaSetValues (XmFileSelectionBoxGetChild (dialog
, XmDIALOG_OK_BUTTON
),
10298 XmNshowAsDefault
, True
, NULL
);
10300 /* If MUSTMATCH is non-nil, disable the file entry field of the
10301 dialog, so that the user must select a file from the files list
10302 box. We can't remove it because we wouldn't have a way to get at
10303 the result file name, then. */
10304 text
= XmFileSelectionBoxGetChild (dialog
, XmDIALOG_TEXT
);
10305 if (!NILP (mustmatch
))
10308 label
= XmFileSelectionBoxGetChild (dialog
, XmDIALOG_SELECTION_LABEL
);
10309 XtSetSensitive (text
, False
);
10310 XtSetSensitive (label
, False
);
10313 /* Manage the dialog, so that list boxes get filled. */
10314 XtManageChild (dialog
);
10316 /* Select DEFAULT_FILENAME in the files list box. DEFAULT_FILENAME
10317 must include the path for this to work. */
10318 list
= XmFileSelectionBoxGetChild (dialog
, XmDIALOG_LIST
);
10319 if (STRINGP (default_filename
))
10321 XmString default_xmstring
;
10325 = XmStringCreateLocalized (SDATA (default_filename
));
10327 if (!XmListItemExists (list
, default_xmstring
))
10329 /* Add a new item if DEFAULT_FILENAME is not in the list. */
10330 XmListAddItem (list
, default_xmstring
, 0);
10334 item_pos
= XmListItemPos (list
, default_xmstring
);
10335 XmStringFree (default_xmstring
);
10337 /* Select the item and scroll it into view. */
10338 XmListSelectPos (list
, item_pos
, True
);
10339 XmListSetPos (list
, item_pos
);
10342 /* Process events until the user presses Cancel or OK. */
10344 while (result
== 0)
10347 XtAppNextEvent (Xt_app_con
, &event
);
10348 (void) x_dispatch_event (&event
, FRAME_X_DISPLAY (f
) );
10351 /* Get the result. */
10352 if (result
== XmCR_OK
)
10357 XtVaGetValues (dialog
, XmNtextString
, &text
, NULL
);
10358 XmStringGetLtoR (text
, XmFONTLIST_DEFAULT_TAG
, &data
);
10359 XmStringFree (text
);
10360 file
= build_string (data
);
10367 XtUnmanageChild (dialog
);
10368 XtDestroyWidget (dialog
);
10372 /* Make "Cancel" equivalent to C-g. */
10374 Fsignal (Qquit
, Qnil
);
10376 return unbind_to (count
, file
);
10379 #endif /* USE_MOTIF */
10383 DEFUN ("x-file-dialog", Fx_file_dialog
, Sx_file_dialog
, 2, 4, 0,
10384 "Read file name, prompting with PROMPT in directory DIR.\n\
10385 Use a file selection dialog.\n\
10386 Select DEFAULT-FILENAME in the dialog's file selection box, if\n\
10387 specified. Don't let the user enter a file name in the file\n\
10388 selection dialog's entry field, if MUSTMATCH is non-nil.")
10389 (prompt
, dir
, default_filename
, mustmatch
)
10390 Lisp_Object prompt
, dir
, default_filename
, mustmatch
;
10392 FRAME_PTR f
= SELECTED_FRAME ();
10394 Lisp_Object file
= Qnil
;
10395 int count
= specpdl_ptr
- specpdl
;
10396 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
, gcpro5
;
10400 GCPRO5 (prompt
, dir
, default_filename
, mustmatch
, file
);
10401 CHECK_STRING (prompt
);
10402 CHECK_STRING (dir
);
10404 /* Prevent redisplay. */
10405 specbind (Qinhibit_redisplay
, Qt
);
10409 if (STRINGP (default_filename
))
10410 cdef_file
= SDATA (default_filename
);
10412 cdef_file
= SDATA (dir
);
10414 fn
= xg_get_file_name (f
, SDATA (prompt
), cdef_file
, ! NILP (mustmatch
));
10418 file
= build_string (fn
);
10425 /* Make "Cancel" equivalent to C-g. */
10427 Fsignal (Qquit
, Qnil
);
10429 return unbind_to (count
, file
);
10432 #endif /* USE_GTK */
10435 /***********************************************************************
10437 ***********************************************************************/
10439 #ifdef HAVE_XKBGETKEYBOARD
10440 #include <X11/XKBlib.h>
10441 #include <X11/keysym.h>
10444 DEFUN ("x-backspace-delete-keys-p", Fx_backspace_delete_keys_p
,
10445 Sx_backspace_delete_keys_p
, 0, 1, 0,
10446 doc
: /* Check if both Backspace and Delete keys are on the keyboard of FRAME.
10447 FRAME nil means use the selected frame.
10448 Value is t if we know that both keys are present, and are mapped to the
10449 usual X keysyms. */)
10453 #ifdef HAVE_XKBGETKEYBOARD
10455 struct frame
*f
= check_x_frame (frame
);
10456 Display
*dpy
= FRAME_X_DISPLAY (f
);
10457 Lisp_Object have_keys
;
10458 int major
, minor
, op
, event
, error
;
10462 /* Check library version in case we're dynamically linked. */
10463 major
= XkbMajorVersion
;
10464 minor
= XkbMinorVersion
;
10465 if (!XkbLibraryVersion (&major
, &minor
))
10471 /* Check that the server supports XKB. */
10472 major
= XkbMajorVersion
;
10473 minor
= XkbMinorVersion
;
10474 if (!XkbQueryExtension (dpy
, &op
, &event
, &error
, &major
, &minor
))
10481 kb
= XkbGetMap (dpy
, XkbAllMapComponentsMask
, XkbUseCoreKbd
);
10484 int delete_keycode
= 0, backspace_keycode
= 0, i
;
10486 if (XkbGetNames (dpy
, XkbAllNamesMask
, kb
) == Success
)
10488 for (i
= kb
->min_key_code
;
10489 (i
< kb
->max_key_code
10490 && (delete_keycode
== 0 || backspace_keycode
== 0));
10493 /* The XKB symbolic key names can be seen most easily in
10494 the PS file generated by `xkbprint -label name
10496 if (bcmp ("DELE", kb
->names
->keys
[i
].name
, 4) == 0)
10497 delete_keycode
= i
;
10498 else if (bcmp ("BKSP", kb
->names
->keys
[i
].name
, 4) == 0)
10499 backspace_keycode
= i
;
10502 XkbFreeNames (kb
, 0, True
);
10505 XkbFreeClientMap (kb
, 0, True
);
10508 && backspace_keycode
10509 && XKeysymToKeycode (dpy
, XK_Delete
) == delete_keycode
10510 && XKeysymToKeycode (dpy
, XK_BackSpace
) == backspace_keycode
)
10515 #else /* not HAVE_XKBGETKEYBOARD */
10517 #endif /* not HAVE_XKBGETKEYBOARD */
10522 /***********************************************************************
10524 ***********************************************************************/
10526 /* Keep this list in the same order as frame_parms in frame.c.
10527 Use 0 for unsupported frame parameters. */
10529 frame_parm_handler x_frame_parm_handlers
[] =
10533 x_set_background_color
,
10534 x_set_border_color
,
10535 x_set_border_width
,
10536 x_set_cursor_color
,
10539 x_set_foreground_color
,
10542 x_set_internal_border_width
,
10543 x_set_menu_bar_lines
,
10545 x_explicitly_set_name
,
10546 x_set_scroll_bar_width
,
10548 x_set_unsplittable
,
10549 x_set_vertical_scroll_bars
,
10551 x_set_tool_bar_lines
,
10552 x_set_scroll_bar_foreground
,
10553 x_set_scroll_bar_background
,
10554 x_set_screen_gamma
,
10555 x_set_line_spacing
,
10556 x_set_fringe_width
,
10557 x_set_fringe_width
,
10565 /* This is zero if not using X windows. */
10568 /* The section below is built by the lisp expression at the top of the file,
10569 just above where these variables are declared. */
10570 /*&&& init symbols here &&&*/
10571 Qnone
= intern ("none");
10572 staticpro (&Qnone
);
10573 Qsuppress_icon
= intern ("suppress-icon");
10574 staticpro (&Qsuppress_icon
);
10575 Qundefined_color
= intern ("undefined-color");
10576 staticpro (&Qundefined_color
);
10577 Qcenter
= intern ("center");
10578 staticpro (&Qcenter
);
10579 Qcompound_text
= intern ("compound-text");
10580 staticpro (&Qcompound_text
);
10581 Qcancel_timer
= intern ("cancel-timer");
10582 staticpro (&Qcancel_timer
);
10583 /* This is the end of symbol initialization. */
10585 /* Text property `display' should be nonsticky by default. */
10586 Vtext_property_default_nonsticky
10587 = Fcons (Fcons (Qdisplay
, Qt
), Vtext_property_default_nonsticky
);
10590 Qlaplace
= intern ("laplace");
10591 staticpro (&Qlaplace
);
10592 Qemboss
= intern ("emboss");
10593 staticpro (&Qemboss
);
10594 Qedge_detection
= intern ("edge-detection");
10595 staticpro (&Qedge_detection
);
10596 Qheuristic
= intern ("heuristic");
10597 staticpro (&Qheuristic
);
10598 QCmatrix
= intern (":matrix");
10599 staticpro (&QCmatrix
);
10600 QCcolor_adjustment
= intern (":color-adjustment");
10601 staticpro (&QCcolor_adjustment
);
10602 QCmask
= intern (":mask");
10603 staticpro (&QCmask
);
10605 Fput (Qundefined_color
, Qerror_conditions
,
10606 Fcons (Qundefined_color
, Fcons (Qerror
, Qnil
)));
10607 Fput (Qundefined_color
, Qerror_message
,
10608 build_string ("Undefined color"));
10610 DEFVAR_BOOL ("cross-disabled-images", &cross_disabled_images
,
10611 doc
: /* Non-nil means always draw a cross over disabled images.
10612 Disabled images are those having an `:conversion disabled' property.
10613 A cross is always drawn on black & white displays. */);
10614 cross_disabled_images
= 0;
10616 DEFVAR_LISP ("x-bitmap-file-path", &Vx_bitmap_file_path
,
10617 doc
: /* List of directories to search for window system bitmap files. */);
10618 Vx_bitmap_file_path
= decode_env_path ((char *) 0, PATH_BITMAPS
);
10620 DEFVAR_LISP ("x-pointer-shape", &Vx_pointer_shape
,
10621 doc
: /* The shape of the pointer when over text.
10622 Changing the value does not affect existing frames
10623 unless you set the mouse color. */);
10624 Vx_pointer_shape
= Qnil
;
10626 #if 0 /* This doesn't really do anything. */
10627 DEFVAR_LISP ("x-nontext-pointer-shape", &Vx_nontext_pointer_shape
,
10628 doc
: /* The shape of the pointer when not over text.
10629 This variable takes effect when you create a new frame
10630 or when you set the mouse color. */);
10632 Vx_nontext_pointer_shape
= Qnil
;
10634 DEFVAR_LISP ("x-hourglass-pointer-shape", &Vx_hourglass_pointer_shape
,
10635 doc
: /* The shape of the pointer when Emacs is busy.
10636 This variable takes effect when you create a new frame
10637 or when you set the mouse color. */);
10638 Vx_hourglass_pointer_shape
= Qnil
;
10640 DEFVAR_BOOL ("display-hourglass", &display_hourglass_p
,
10641 doc
: /* Non-zero means Emacs displays an hourglass pointer on window systems. */);
10642 display_hourglass_p
= 1;
10644 DEFVAR_LISP ("hourglass-delay", &Vhourglass_delay
,
10645 doc
: /* *Seconds to wait before displaying an hourglass pointer.
10646 Value must be an integer or float. */);
10647 Vhourglass_delay
= make_number (DEFAULT_HOURGLASS_DELAY
);
10649 #if 0 /* This doesn't really do anything. */
10650 DEFVAR_LISP ("x-mode-pointer-shape", &Vx_mode_pointer_shape
,
10651 doc
: /* The shape of the pointer when over the mode line.
10652 This variable takes effect when you create a new frame
10653 or when you set the mouse color. */);
10655 Vx_mode_pointer_shape
= Qnil
;
10657 DEFVAR_LISP ("x-sensitive-text-pointer-shape",
10658 &Vx_sensitive_text_pointer_shape
,
10659 doc
: /* The shape of the pointer when over mouse-sensitive text.
10660 This variable takes effect when you create a new frame
10661 or when you set the mouse color. */);
10662 Vx_sensitive_text_pointer_shape
= Qnil
;
10664 DEFVAR_LISP ("x-window-horizontal-drag-cursor",
10665 &Vx_window_horizontal_drag_shape
,
10666 doc
: /* Pointer shape to use for indicating a window can be dragged horizontally.
10667 This variable takes effect when you create a new frame
10668 or when you set the mouse color. */);
10669 Vx_window_horizontal_drag_shape
= Qnil
;
10671 DEFVAR_LISP ("x-cursor-fore-pixel", &Vx_cursor_fore_pixel
,
10672 doc
: /* A string indicating the foreground color of the cursor box. */);
10673 Vx_cursor_fore_pixel
= Qnil
;
10675 DEFVAR_LISP ("x-max-tooltip-size", &Vx_max_tooltip_size
,
10676 doc
: /* Maximum size for tooltips. Value is a pair (COLUMNS . ROWS).
10677 Text larger than this is clipped. */);
10678 Vx_max_tooltip_size
= Fcons (make_number (80), make_number (40));
10680 DEFVAR_LISP ("x-no-window-manager", &Vx_no_window_manager
,
10681 doc
: /* Non-nil if no X window manager is in use.
10682 Emacs doesn't try to figure this out; this is always nil
10683 unless you set it to something else. */);
10684 /* We don't have any way to find this out, so set it to nil
10685 and maybe the user would like to set it to t. */
10686 Vx_no_window_manager
= Qnil
;
10688 DEFVAR_LISP ("x-pixel-size-width-font-regexp",
10689 &Vx_pixel_size_width_font_regexp
,
10690 doc
: /* Regexp matching a font name whose width is the same as `PIXEL_SIZE'.
10692 Since Emacs gets width of a font matching with this regexp from
10693 PIXEL_SIZE field of the name, font finding mechanism gets faster for
10694 such a font. This is especially effective for such large fonts as
10695 Chinese, Japanese, and Korean. */);
10696 Vx_pixel_size_width_font_regexp
= Qnil
;
10698 DEFVAR_LISP ("image-cache-eviction-delay", &Vimage_cache_eviction_delay
,
10699 doc
: /* Time after which cached images are removed from the cache.
10700 When an image has not been displayed this many seconds, remove it
10701 from the image cache. Value must be an integer or nil with nil
10702 meaning don't clear the cache. */);
10703 Vimage_cache_eviction_delay
= make_number (30 * 60);
10705 #ifdef USE_X_TOOLKIT
10706 Fprovide (intern ("x-toolkit"), Qnil
);
10708 Fprovide (intern ("motif"), Qnil
);
10710 DEFVAR_LISP ("motif-version-string", &Vmotif_version_string
,
10711 doc
: /* Version info for LessTif/Motif. */);
10712 Vmotif_version_string
= build_string (XmVERSION_STRING
);
10713 #endif /* USE_MOTIF */
10714 #endif /* USE_X_TOOLKIT */
10716 /* X window properties. */
10717 defsubr (&Sx_change_window_property
);
10718 defsubr (&Sx_delete_window_property
);
10719 defsubr (&Sx_window_property
);
10721 defsubr (&Sxw_display_color_p
);
10722 defsubr (&Sx_display_grayscale_p
);
10723 defsubr (&Sxw_color_defined_p
);
10724 defsubr (&Sxw_color_values
);
10725 defsubr (&Sx_server_max_request_size
);
10726 defsubr (&Sx_server_vendor
);
10727 defsubr (&Sx_server_version
);
10728 defsubr (&Sx_display_pixel_width
);
10729 defsubr (&Sx_display_pixel_height
);
10730 defsubr (&Sx_display_mm_width
);
10731 defsubr (&Sx_display_mm_height
);
10732 defsubr (&Sx_display_screens
);
10733 defsubr (&Sx_display_planes
);
10734 defsubr (&Sx_display_color_cells
);
10735 defsubr (&Sx_display_visual_class
);
10736 defsubr (&Sx_display_backing_store
);
10737 defsubr (&Sx_display_save_under
);
10738 defsubr (&Sx_create_frame
);
10739 defsubr (&Sx_open_connection
);
10740 defsubr (&Sx_close_connection
);
10741 defsubr (&Sx_display_list
);
10742 defsubr (&Sx_synchronize
);
10743 defsubr (&Sx_focus_frame
);
10744 defsubr (&Sx_backspace_delete_keys_p
);
10746 /* Setting callback functions for fontset handler. */
10747 get_font_info_func
= x_get_font_info
;
10749 #if 0 /* This function pointer doesn't seem to be used anywhere.
10750 And the pointer assigned has the wrong type, anyway. */
10751 list_fonts_func
= x_list_fonts
;
10754 load_font_func
= x_load_font
;
10755 find_ccl_program_func
= x_find_ccl_program
;
10756 query_font_func
= x_query_font
;
10757 set_frame_fontset_func
= x_set_font
;
10758 check_window_system_func
= check_x
;
10761 Qxbm
= intern ("xbm");
10763 QCconversion
= intern (":conversion");
10764 staticpro (&QCconversion
);
10765 QCheuristic_mask
= intern (":heuristic-mask");
10766 staticpro (&QCheuristic_mask
);
10767 QCcolor_symbols
= intern (":color-symbols");
10768 staticpro (&QCcolor_symbols
);
10769 QCascent
= intern (":ascent");
10770 staticpro (&QCascent
);
10771 QCmargin
= intern (":margin");
10772 staticpro (&QCmargin
);
10773 QCrelief
= intern (":relief");
10774 staticpro (&QCrelief
);
10775 Qpostscript
= intern ("postscript");
10776 staticpro (&Qpostscript
);
10777 QCloader
= intern (":loader");
10778 staticpro (&QCloader
);
10779 QCbounding_box
= intern (":bounding-box");
10780 staticpro (&QCbounding_box
);
10781 QCpt_width
= intern (":pt-width");
10782 staticpro (&QCpt_width
);
10783 QCpt_height
= intern (":pt-height");
10784 staticpro (&QCpt_height
);
10785 QCindex
= intern (":index");
10786 staticpro (&QCindex
);
10787 Qpbm
= intern ("pbm");
10791 Qxpm
= intern ("xpm");
10796 Qjpeg
= intern ("jpeg");
10797 staticpro (&Qjpeg
);
10801 Qtiff
= intern ("tiff");
10802 staticpro (&Qtiff
);
10806 Qgif
= intern ("gif");
10811 Qpng
= intern ("png");
10815 defsubr (&Sclear_image_cache
);
10816 defsubr (&Simage_size
);
10817 defsubr (&Simage_mask_p
);
10819 hourglass_atimer
= NULL
;
10820 hourglass_shown_p
= 0;
10822 defsubr (&Sx_show_tip
);
10823 defsubr (&Sx_hide_tip
);
10825 staticpro (&tip_timer
);
10827 staticpro (&tip_frame
);
10829 last_show_tip_args
= Qnil
;
10830 staticpro (&last_show_tip_args
);
10833 defsubr (&Sx_file_dialog
);
10841 image_types
= NULL
;
10842 Vimage_types
= Qnil
;
10844 define_image_type (&xbm_type
);
10845 define_image_type (&gs_type
);
10846 define_image_type (&pbm_type
);
10849 define_image_type (&xpm_type
);
10853 define_image_type (&jpeg_type
);
10857 define_image_type (&tiff_type
);
10861 define_image_type (&gif_type
);
10865 define_image_type (&png_type
);
10869 #endif /* HAVE_X_WINDOWS */