1 /* Functions for the X window system.
2 Copyright (C) 1989, 92, 93, 94, 95, 96, 97, 98, 99, 2000, 01, 02, 03
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"
56 #include <sys/types.h>
60 #if 1 /* Used to be #ifdef EMACS_BITMAP_FILES, but this should always work. */
61 #include "bitmaps/gray.xbm"
63 #include <X11/bitmaps/gray>
66 #include "[.bitmaps]gray.xbm"
74 #include <X11/Shell.h>
77 #include <X11/Xaw/Paned.h>
78 #include <X11/Xaw/Label.h>
79 #endif /* USE_MOTIF */
82 #undef USG /* ####KLUDGE for Solaris 2.2 and up */
91 #include "../lwlib/lwlib.h"
95 #include <Xm/DialogS.h>
96 #include <Xm/FileSB.h>
99 /* Do the EDITRES protocol if running X11R5
100 Exception: HP-UX (at least version A.09.05) has X11R5 without EditRes */
102 #if (XtSpecificationRelease >= 5) && !defined(NO_EDITRES)
104 extern void _XEditResCheckMessages ();
105 #endif /* R5 + Athena */
107 /* Unique id counter for widgets created by the Lucid Widget Library. */
109 extern LWLIB_ID widget_id_tick
;
112 /* This is part of a kludge--see lwlib/xlwmenu.c. */
113 extern XFontStruct
*xlwmenu_default_font
;
116 extern void free_frame_menubar ();
117 extern double atof ();
121 /* LessTif/Motif version info. */
123 static Lisp_Object Vmotif_version_string
;
125 #endif /* USE_MOTIF */
127 #endif /* USE_X_TOOLKIT */
131 /* GTK+ version info */
133 static Lisp_Object Vgtk_version_string
;
138 #define MAXREQUEST(dpy) (XMaxRequestSize (dpy))
140 #define MAXREQUEST(dpy) ((dpy)->max_request_size)
143 /* The gray bitmap `bitmaps/gray'. This is done because xterm.c uses
144 it, and including `bitmaps/gray' more than once is a problem when
145 config.h defines `static' as an empty replacement string. */
147 int gray_bitmap_width
= gray_width
;
148 int gray_bitmap_height
= gray_height
;
149 char *gray_bitmap_bits
= gray_bits
;
151 /* Non-zero means we're allowed to display an hourglass cursor. */
153 int display_hourglass_p
;
155 /* The background and shape of the mouse pointer, and shape when not
156 over text or in the modeline. */
158 Lisp_Object Vx_pointer_shape
, Vx_nontext_pointer_shape
, Vx_mode_pointer_shape
;
159 Lisp_Object Vx_hourglass_pointer_shape
;
161 /* The shape when over mouse-sensitive text. */
163 Lisp_Object Vx_sensitive_text_pointer_shape
;
165 /* If non-nil, the pointer shape to indicate that windows can be
166 dragged horizontally. */
168 Lisp_Object Vx_window_horizontal_drag_shape
;
170 /* Color of chars displayed in cursor box. */
172 Lisp_Object Vx_cursor_fore_pixel
;
174 /* Nonzero if using X. */
178 /* Non nil if no window manager is in use. */
180 Lisp_Object Vx_no_window_manager
;
182 /* Search path for bitmap files. */
184 Lisp_Object Vx_bitmap_file_path
;
186 /* Regexp matching a font name whose width is the same as `PIXEL_SIZE'. */
188 Lisp_Object Vx_pixel_size_width_font_regexp
;
191 Lisp_Object Qsuppress_icon
;
192 Lisp_Object Qundefined_color
;
194 Lisp_Object Qcompound_text
, Qcancel_timer
;
198 extern Lisp_Object Vwindow_system_version
;
200 /* The below are defined in frame.c. */
203 int image_cache_refcount
, dpyinfo_refcount
;
208 /* Error if we are not connected to X. */
214 error ("X windows are not in use or not initialized");
217 /* Nonzero if we can use mouse menus.
218 You should not call this unless HAVE_MENUS is defined. */
226 /* Extract a frame as a FRAME_PTR, defaulting to the selected frame
227 and checking validity for X. */
230 check_x_frame (frame
)
236 frame
= selected_frame
;
237 CHECK_LIVE_FRAME (frame
);
240 error ("Non-X frame used");
244 /* Let the user specify an X display with a frame.
245 nil stands for the selected frame--or, if that is not an X frame,
246 the first X display on the list. */
248 struct x_display_info
*
249 check_x_display_info (frame
)
252 struct x_display_info
*dpyinfo
= NULL
;
256 struct frame
*sf
= XFRAME (selected_frame
);
258 if (FRAME_X_P (sf
) && FRAME_LIVE_P (sf
))
259 dpyinfo
= FRAME_X_DISPLAY_INFO (sf
);
260 else if (x_display_list
!= 0)
261 dpyinfo
= x_display_list
;
263 error ("X windows are not in use or not initialized");
265 else if (STRINGP (frame
))
266 dpyinfo
= x_display_info_for_name (frame
);
269 FRAME_PTR f
= check_x_frame (frame
);
270 dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
277 /* Return the Emacs frame-object corresponding to an X window.
278 It could be the frame's main window or an icon window. */
280 /* This function can be called during GC, so use GC_xxx type test macros. */
283 x_window_to_frame (dpyinfo
, wdesc
)
284 struct x_display_info
*dpyinfo
;
287 Lisp_Object tail
, frame
;
290 for (tail
= Vframe_list
; GC_CONSP (tail
); tail
= XCDR (tail
))
293 if (!GC_FRAMEP (frame
))
296 if (!FRAME_X_P (f
) || FRAME_X_DISPLAY_INFO (f
) != dpyinfo
)
298 if (f
->output_data
.x
->hourglass_window
== wdesc
)
301 if ((f
->output_data
.x
->edit_widget
302 && XtWindow (f
->output_data
.x
->edit_widget
) == wdesc
)
303 /* A tooltip frame? */
304 || (!f
->output_data
.x
->edit_widget
305 && FRAME_X_WINDOW (f
) == wdesc
)
306 || f
->output_data
.x
->icon_desc
== wdesc
)
308 #else /* not USE_X_TOOLKIT */
310 if (f
->output_data
.x
->edit_widget
)
312 GtkWidget
*gwdesc
= xg_win_to_widget (dpyinfo
->display
, wdesc
);
313 struct x_output
*x
= f
->output_data
.x
;
314 if (gwdesc
!= 0 && gwdesc
== x
->edit_widget
)
318 if (FRAME_X_WINDOW (f
) == wdesc
319 || f
->output_data
.x
->icon_desc
== wdesc
)
321 #endif /* not USE_X_TOOLKIT */
326 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
327 /* Like x_window_to_frame but also compares the window with the widget's
331 x_any_window_to_frame (dpyinfo
, wdesc
)
332 struct x_display_info
*dpyinfo
;
335 Lisp_Object tail
, frame
;
336 struct frame
*f
, *found
;
340 for (tail
= Vframe_list
; GC_CONSP (tail
) && !found
; tail
= XCDR (tail
))
343 if (!GC_FRAMEP (frame
))
347 if (FRAME_X_P (f
) && FRAME_X_DISPLAY_INFO (f
) == dpyinfo
)
349 /* This frame matches if the window is any of its widgets. */
350 x
= f
->output_data
.x
;
351 if (x
->hourglass_window
== wdesc
)
356 GtkWidget
*gwdesc
= xg_win_to_widget (dpyinfo
->display
, wdesc
);
358 && (gwdesc
== x
->widget
359 || gwdesc
== x
->edit_widget
360 || gwdesc
== x
->vbox_widget
361 || gwdesc
== x
->menubar_widget
))
364 if (wdesc
== XtWindow (x
->widget
)
365 || wdesc
== XtWindow (x
->column_widget
)
366 || wdesc
== XtWindow (x
->edit_widget
))
368 /* Match if the window is this frame's menubar. */
369 else if (lw_window_is_in_menubar (wdesc
, x
->menubar_widget
))
373 else if (FRAME_X_WINDOW (f
) == wdesc
)
374 /* A tooltip frame. */
382 /* Likewise, but exclude the menu bar widget. */
385 x_non_menubar_window_to_frame (dpyinfo
, wdesc
)
386 struct x_display_info
*dpyinfo
;
389 Lisp_Object tail
, frame
;
393 for (tail
= Vframe_list
; GC_CONSP (tail
); tail
= XCDR (tail
))
396 if (!GC_FRAMEP (frame
))
399 if (!FRAME_X_P (f
) || FRAME_X_DISPLAY_INFO (f
) != dpyinfo
)
401 x
= f
->output_data
.x
;
402 /* This frame matches if the window is any of its widgets. */
403 if (x
->hourglass_window
== wdesc
)
408 GtkWidget
*gwdesc
= xg_win_to_widget (dpyinfo
->display
, wdesc
);
410 && (gwdesc
== x
->widget
411 || gwdesc
== x
->edit_widget
412 || gwdesc
== x
->vbox_widget
))
415 if (wdesc
== XtWindow (x
->widget
)
416 || wdesc
== XtWindow (x
->column_widget
)
417 || wdesc
== XtWindow (x
->edit_widget
))
421 else if (FRAME_X_WINDOW (f
) == wdesc
)
422 /* A tooltip frame. */
428 /* Likewise, but consider only the menu bar widget. */
431 x_menubar_window_to_frame (dpyinfo
, wdesc
)
432 struct x_display_info
*dpyinfo
;
435 Lisp_Object tail
, frame
;
439 for (tail
= Vframe_list
; GC_CONSP (tail
); tail
= XCDR (tail
))
442 if (!GC_FRAMEP (frame
))
445 if (!FRAME_X_P (f
) || FRAME_X_DISPLAY_INFO (f
) != dpyinfo
)
447 x
= f
->output_data
.x
;
448 /* Match if the window is this frame's menubar. */
450 if (x
->menubar_widget
)
452 GtkWidget
*gwdesc
= xg_win_to_widget (dpyinfo
->display
, wdesc
);
457 && (gwdesc
== x
->menubar_widget
458 || gtk_widget_get_parent (gwdesc
) == x
->menubar_widget
))
464 if (x
->menubar_widget
465 && lw_window_is_in_menubar (wdesc
, x
->menubar_widget
))
472 /* Return the frame whose principal (outermost) window is WDESC.
473 If WDESC is some other (smaller) window, we return 0. */
476 x_top_window_to_frame (dpyinfo
, wdesc
)
477 struct x_display_info
*dpyinfo
;
480 Lisp_Object tail
, frame
;
484 for (tail
= Vframe_list
; GC_CONSP (tail
); tail
= XCDR (tail
))
487 if (!GC_FRAMEP (frame
))
490 if (!FRAME_X_P (f
) || FRAME_X_DISPLAY_INFO (f
) != dpyinfo
)
492 x
= f
->output_data
.x
;
496 /* This frame matches if the window is its topmost widget. */
498 GtkWidget
*gwdesc
= xg_win_to_widget (dpyinfo
->display
, wdesc
);
499 if (gwdesc
== x
->widget
)
502 if (wdesc
== XtWindow (x
->widget
))
504 #if 0 /* I don't know why it did this,
505 but it seems logically wrong,
506 and it causes trouble for MapNotify events. */
507 /* Match if the window is this frame's menubar. */
508 if (x
->menubar_widget
509 && wdesc
== XtWindow (x
->menubar_widget
))
514 else if (FRAME_X_WINDOW (f
) == wdesc
)
520 #endif /* USE_X_TOOLKIT || USE_GTK */
524 /* Code to deal with bitmaps. Bitmaps are referenced by their bitmap
525 id, which is just an int that this section returns. Bitmaps are
526 reference counted so they can be shared among frames.
528 Bitmap indices are guaranteed to be > 0, so a negative number can
529 be used to indicate no bitmap.
531 If you use x_create_bitmap_from_data, then you must keep track of
532 the bitmaps yourself. That is, creating a bitmap from the same
533 data more than once will not be caught. */
536 /* Functions to access the contents of a bitmap, given an id. */
539 x_bitmap_height (f
, id
)
543 return FRAME_X_DISPLAY_INFO (f
)->bitmaps
[id
- 1].height
;
547 x_bitmap_width (f
, id
)
551 return FRAME_X_DISPLAY_INFO (f
)->bitmaps
[id
- 1].width
;
555 x_bitmap_pixmap (f
, id
)
559 return FRAME_X_DISPLAY_INFO (f
)->bitmaps
[id
- 1].pixmap
;
563 x_bitmap_mask (f
, id
)
567 return FRAME_X_DISPLAY_INFO (f
)->bitmaps
[id
- 1].mask
;
571 /* Allocate a new bitmap record. Returns index of new record. */
574 x_allocate_bitmap_record (f
)
577 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
580 if (dpyinfo
->bitmaps
== NULL
)
582 dpyinfo
->bitmaps_size
= 10;
584 = (struct x_bitmap_record
*) xmalloc (dpyinfo
->bitmaps_size
* sizeof (struct x_bitmap_record
));
585 dpyinfo
->bitmaps_last
= 1;
589 if (dpyinfo
->bitmaps_last
< dpyinfo
->bitmaps_size
)
590 return ++dpyinfo
->bitmaps_last
;
592 for (i
= 0; i
< dpyinfo
->bitmaps_size
; ++i
)
593 if (dpyinfo
->bitmaps
[i
].refcount
== 0)
596 dpyinfo
->bitmaps_size
*= 2;
598 = (struct x_bitmap_record
*) xrealloc (dpyinfo
->bitmaps
,
599 dpyinfo
->bitmaps_size
* sizeof (struct x_bitmap_record
));
600 return ++dpyinfo
->bitmaps_last
;
603 /* Add one reference to the reference count of the bitmap with id ID. */
606 x_reference_bitmap (f
, id
)
610 ++FRAME_X_DISPLAY_INFO (f
)->bitmaps
[id
- 1].refcount
;
613 /* Create a bitmap for frame F from a HEIGHT x WIDTH array of bits at BITS. */
616 x_create_bitmap_from_data (f
, bits
, width
, height
)
619 unsigned int width
, height
;
621 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
625 bitmap
= XCreateBitmapFromData (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
626 bits
, width
, height
);
633 id
= x_allocate_bitmap_record (f
);
634 dpyinfo
->bitmaps
[id
- 1].pixmap
= bitmap
;
635 dpyinfo
->bitmaps
[id
- 1].have_mask
= 0;
636 dpyinfo
->bitmaps
[id
- 1].file
= NULL
;
637 dpyinfo
->bitmaps
[id
- 1].refcount
= 1;
638 dpyinfo
->bitmaps
[id
- 1].depth
= 1;
639 dpyinfo
->bitmaps
[id
- 1].height
= height
;
640 dpyinfo
->bitmaps
[id
- 1].width
= width
;
645 /* Create bitmap from file FILE for frame F. */
648 x_create_bitmap_from_file (f
, file
)
652 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
653 unsigned int width
, height
;
655 int xhot
, yhot
, result
, id
;
660 /* Look for an existing bitmap with the same name. */
661 for (id
= 0; id
< dpyinfo
->bitmaps_last
; ++id
)
663 if (dpyinfo
->bitmaps
[id
].refcount
664 && dpyinfo
->bitmaps
[id
].file
665 && !strcmp (dpyinfo
->bitmaps
[id
].file
, (char *) SDATA (file
)))
667 ++dpyinfo
->bitmaps
[id
].refcount
;
672 /* Search bitmap-file-path for the file, if appropriate. */
673 fd
= openp (Vx_bitmap_file_path
, file
, Qnil
, &found
, Qnil
);
678 filename
= (char *) SDATA (found
);
680 result
= XReadBitmapFile (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
681 filename
, &width
, &height
, &bitmap
, &xhot
, &yhot
);
682 if (result
!= BitmapSuccess
)
685 id
= x_allocate_bitmap_record (f
);
686 dpyinfo
->bitmaps
[id
- 1].pixmap
= bitmap
;
687 dpyinfo
->bitmaps
[id
- 1].have_mask
= 0;
688 dpyinfo
->bitmaps
[id
- 1].refcount
= 1;
689 dpyinfo
->bitmaps
[id
- 1].file
690 = (char *) xmalloc (SBYTES (file
) + 1);
691 dpyinfo
->bitmaps
[id
- 1].depth
= 1;
692 dpyinfo
->bitmaps
[id
- 1].height
= height
;
693 dpyinfo
->bitmaps
[id
- 1].width
= width
;
694 strcpy (dpyinfo
->bitmaps
[id
- 1].file
, SDATA (file
));
699 /* Remove reference to bitmap with id number ID. */
702 x_destroy_bitmap (f
, id
)
706 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
710 --dpyinfo
->bitmaps
[id
- 1].refcount
;
711 if (dpyinfo
->bitmaps
[id
- 1].refcount
== 0)
714 XFreePixmap (FRAME_X_DISPLAY (f
), dpyinfo
->bitmaps
[id
- 1].pixmap
);
715 if (dpyinfo
->bitmaps
[id
- 1].have_mask
)
716 XFreePixmap (FRAME_X_DISPLAY (f
), dpyinfo
->bitmaps
[id
- 1].mask
);
717 if (dpyinfo
->bitmaps
[id
- 1].file
)
719 xfree (dpyinfo
->bitmaps
[id
- 1].file
);
720 dpyinfo
->bitmaps
[id
- 1].file
= NULL
;
727 /* Free all the bitmaps for the display specified by DPYINFO. */
730 x_destroy_all_bitmaps (dpyinfo
)
731 struct x_display_info
*dpyinfo
;
734 for (i
= 0; i
< dpyinfo
->bitmaps_last
; i
++)
735 if (dpyinfo
->bitmaps
[i
].refcount
> 0)
737 XFreePixmap (dpyinfo
->display
, dpyinfo
->bitmaps
[i
].pixmap
);
738 if (dpyinfo
->bitmaps
[i
].have_mask
)
739 XFreePixmap (dpyinfo
->display
, dpyinfo
->bitmaps
[i
].mask
);
740 if (dpyinfo
->bitmaps
[i
].file
)
741 xfree (dpyinfo
->bitmaps
[i
].file
);
743 dpyinfo
->bitmaps_last
= 0;
749 /* Useful functions defined in the section
750 `Image type independent image structures' below. */
752 static unsigned long four_corners_best
P_ ((XImage
*ximg
, unsigned long width
,
753 unsigned long height
));
755 static int x_create_x_image_and_pixmap
P_ ((struct frame
*f
, int width
, int height
,
756 int depth
, XImage
**ximg
,
759 static void x_destroy_x_image
P_ ((XImage
*ximg
));
762 /* Create a mask of a bitmap. Note is this not a perfect mask.
763 It's nicer with some borders in this context */
766 x_create_bitmap_mask (f
, id
)
771 XImage
*ximg
, *mask_img
;
772 unsigned long width
, height
;
775 unsigned long x
, y
, xp
, xm
, yp
, ym
;
778 int depth
= DefaultDepthOfScreen (FRAME_X_SCREEN (f
));
779 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
784 pixmap
= x_bitmap_pixmap (f
, id
);
785 width
= x_bitmap_width (f
, id
);
786 height
= x_bitmap_height (f
, id
);
789 ximg
= XGetImage (FRAME_X_DISPLAY (f
), pixmap
, 0, 0, width
, height
,
798 result
= x_create_x_image_and_pixmap (f
, width
, height
, 1, &mask_img
, &mask
);
803 XDestroyImage (ximg
);
807 bg
= four_corners_best (ximg
, width
, height
);
809 for (y
= 0; y
< ximg
->height
; ++y
)
811 for (x
= 0; x
< ximg
->width
; ++x
)
813 xp
= x
!= ximg
->width
- 1 ? x
+ 1 : 0;
814 xm
= x
!= 0 ? x
- 1 : ximg
->width
- 1;
815 yp
= y
!= ximg
->height
- 1 ? y
+ 1 : 0;
816 ym
= y
!= 0 ? y
- 1 : ximg
->height
- 1;
817 if (XGetPixel (ximg
, x
, y
) == bg
818 && XGetPixel (ximg
, x
, yp
) == bg
819 && XGetPixel (ximg
, x
, ym
) == bg
820 && XGetPixel (ximg
, xp
, y
) == bg
821 && XGetPixel (ximg
, xp
, yp
) == bg
822 && XGetPixel (ximg
, xp
, ym
) == bg
823 && XGetPixel (ximg
, xm
, y
) == bg
824 && XGetPixel (ximg
, xm
, yp
) == bg
825 && XGetPixel (ximg
, xm
, ym
) == bg
)
826 XPutPixel (mask_img
, x
, y
, 0);
828 XPutPixel (mask_img
, x
, y
, 1);
832 xassert (interrupt_input_blocked
);
833 gc
= XCreateGC (FRAME_X_DISPLAY (f
), mask
, 0, NULL
);
834 XPutImage (FRAME_X_DISPLAY (f
), mask
, gc
, mask_img
, 0, 0, 0, 0,
836 XFreeGC (FRAME_X_DISPLAY (f
), gc
);
838 dpyinfo
->bitmaps
[id
- 1].have_mask
= 1;
839 dpyinfo
->bitmaps
[id
- 1].mask
= mask
;
841 XDestroyImage (ximg
);
842 x_destroy_x_image (mask_img
);
847 static Lisp_Object unwind_create_frame
P_ ((Lisp_Object
));
848 static Lisp_Object unwind_create_tip_frame
P_ ((Lisp_Object
));
849 static void x_disable_image
P_ ((struct frame
*, struct image
*));
851 void x_set_foreground_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
852 static void x_set_wait_for_wm
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
853 void x_set_background_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
854 void x_set_mouse_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
855 void x_set_cursor_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
856 void x_set_border_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
857 void x_set_cursor_type
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
858 void x_set_icon_type
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
859 void x_set_icon_name
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
860 void x_explicitly_set_name
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
861 void x_set_menu_bar_lines
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
862 void x_set_title
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
863 void x_set_tool_bar_lines
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
864 void x_set_scroll_bar_foreground
P_ ((struct frame
*, Lisp_Object
,
866 void x_set_scroll_bar_background
P_ ((struct frame
*, Lisp_Object
,
868 static Lisp_Object x_default_scroll_bar_color_parameter
P_ ((struct frame
*,
873 static void x_edge_detection
P_ ((struct frame
*, struct image
*, Lisp_Object
,
875 static void init_color_table
P_ ((void));
876 static void free_color_table
P_ ((void));
877 static unsigned long *colors_in_color_table
P_ ((int *n
));
878 static unsigned long lookup_rgb_color
P_ ((struct frame
*f
, int r
, int g
, int b
));
879 static unsigned long lookup_pixel_color
P_ ((struct frame
*f
, unsigned long p
));
885 /* Store the screen positions of frame F into XPTR and YPTR.
886 These are the positions of the containing window manager window,
887 not Emacs's own window. */
890 x_real_positions (f
, xptr
, yptr
)
894 int win_x
, win_y
, outer_x
, outer_y
;
895 int real_x
= 0, real_y
= 0;
897 Window win
= f
->output_data
.x
->parent_desc
;
903 count
= x_catch_errors (FRAME_X_DISPLAY (f
));
905 if (win
== FRAME_X_DISPLAY_INFO (f
)->root_window
)
906 win
= FRAME_OUTER_WINDOW (f
);
908 /* This loop traverses up the containment tree until we hit the root
909 window. Window managers may intersect many windows between our window
910 and the root window. The window we find just before the root window
911 should be the outer WM window. */
914 Window wm_window
, rootw
;
915 Window
*tmp_children
;
916 unsigned int tmp_nchildren
;
919 success
= XQueryTree (FRAME_X_DISPLAY (f
), win
, &rootw
,
920 &wm_window
, &tmp_children
, &tmp_nchildren
);
922 had_errors
= x_had_errors_p (FRAME_X_DISPLAY (f
));
924 /* Don't free tmp_children if XQueryTree failed. */
928 XFree ((char *) tmp_children
);
930 if (wm_window
== rootw
|| had_errors
)
941 /* Get the real coordinates for the WM window upper left corner */
942 XGetGeometry (FRAME_X_DISPLAY (f
), win
,
943 &rootw
, &real_x
, &real_y
, &ign
, &ign
, &ign
, &ign
);
945 /* Translate real coordinates to coordinates relative to our
946 window. For our window, the upper left corner is 0, 0.
947 Since the upper left corner of the WM window is outside
948 our window, win_x and win_y will be negative:
950 ------------------ ---> x
952 | ----------------- v y
955 XTranslateCoordinates (FRAME_X_DISPLAY (f
),
957 /* From-window, to-window. */
958 FRAME_X_DISPLAY_INFO (f
)->root_window
,
961 /* From-position, to-position. */
962 real_x
, real_y
, &win_x
, &win_y
,
967 if (FRAME_X_WINDOW (f
) == FRAME_OUTER_WINDOW (f
))
974 XTranslateCoordinates (FRAME_X_DISPLAY (f
),
976 /* From-window, to-window. */
977 FRAME_X_DISPLAY_INFO (f
)->root_window
,
978 FRAME_OUTER_WINDOW (f
),
980 /* From-position, to-position. */
981 real_x
, real_y
, &outer_x
, &outer_y
,
987 had_errors
= x_had_errors_p (FRAME_X_DISPLAY (f
));
990 x_uncatch_errors (FRAME_X_DISPLAY (f
), count
);
994 if (had_errors
) return;
996 f
->x_pixels_diff
= -win_x
;
997 f
->y_pixels_diff
= -win_y
;
999 FRAME_X_OUTPUT (f
)->x_pixels_outer_diff
= -outer_x
;
1000 FRAME_X_OUTPUT (f
)->y_pixels_outer_diff
= -outer_y
;
1009 /* Gamma-correct COLOR on frame F. */
1012 gamma_correct (f
, color
)
1018 color
->red
= pow (color
->red
/ 65535.0, f
->gamma
) * 65535.0 + 0.5;
1019 color
->green
= pow (color
->green
/ 65535.0, f
->gamma
) * 65535.0 + 0.5;
1020 color
->blue
= pow (color
->blue
/ 65535.0, f
->gamma
) * 65535.0 + 0.5;
1025 /* Decide if color named COLOR_NAME is valid for use on frame F. If
1026 so, return the RGB values in COLOR. If ALLOC_P is non-zero,
1027 allocate the color. Value is zero if COLOR_NAME is invalid, or
1028 no color could be allocated. */
1031 x_defined_color (f
, color_name
, color
, alloc_p
)
1038 Display
*dpy
= FRAME_X_DISPLAY (f
);
1039 Colormap cmap
= FRAME_X_COLORMAP (f
);
1042 success_p
= XParseColor (dpy
, cmap
, color_name
, color
);
1043 if (success_p
&& alloc_p
)
1044 success_p
= x_alloc_nearest_color (f
, cmap
, color
);
1051 /* Return the pixel color value for color COLOR_NAME on frame F. If F
1052 is a monochrome frame, return MONO_COLOR regardless of what ARG says.
1053 Signal an error if color can't be allocated. */
1056 x_decode_color (f
, color_name
, mono_color
)
1058 Lisp_Object color_name
;
1063 CHECK_STRING (color_name
);
1065 #if 0 /* Don't do this. It's wrong when we're not using the default
1066 colormap, it makes freeing difficult, and it's probably not
1067 an important optimization. */
1068 if (strcmp (SDATA (color_name
), "black") == 0)
1069 return BLACK_PIX_DEFAULT (f
);
1070 else if (strcmp (SDATA (color_name
), "white") == 0)
1071 return WHITE_PIX_DEFAULT (f
);
1074 /* Return MONO_COLOR for monochrome frames. */
1075 if (FRAME_X_DISPLAY_INFO (f
)->n_planes
== 1)
1078 /* x_defined_color is responsible for coping with failures
1079 by looking for a near-miss. */
1080 if (x_defined_color (f
, SDATA (color_name
), &cdef
, 1))
1083 Fsignal (Qerror
, Fcons (build_string ("Undefined color"),
1084 Fcons (color_name
, Qnil
)));
1090 /* Change the `wait-for-wm' frame parameter of frame F. OLD_VALUE is
1091 the previous value of that parameter, NEW_VALUE is the new value.
1092 See also the comment of wait_for_wm in struct x_output. */
1095 x_set_wait_for_wm (f
, new_value
, old_value
)
1097 Lisp_Object new_value
, old_value
;
1099 f
->output_data
.x
->wait_for_wm
= !NILP (new_value
);
1104 static Lisp_Object x_find_image_file
P_ ((Lisp_Object file
));
1106 /* Set icon from FILE for frame F. By using GTK functions the icon
1107 may be any format that GdkPixbuf knows about, i.e. not just bitmaps. */
1110 xg_set_icon (f
, file
)
1114 struct gcpro gcpro1
;
1120 found
= x_find_image_file (file
);
1128 filename
= SDATA (found
);
1131 pixbuf
= gdk_pixbuf_new_from_file (filename
, &err
);
1135 gtk_window_set_icon (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f
)),
1137 g_object_unref (pixbuf
);
1150 #endif /* USE_GTK */
1153 /* Functions called only from `x_set_frame_param'
1154 to set individual parameters.
1156 If FRAME_X_WINDOW (f) is 0,
1157 the frame is being created and its X-window does not exist yet.
1158 In that case, just record the parameter's new value
1159 in the standard place; do not attempt to change the window. */
1162 x_set_foreground_color (f
, arg
, oldval
)
1164 Lisp_Object arg
, oldval
;
1166 struct x_output
*x
= f
->output_data
.x
;
1167 unsigned long fg
, old_fg
;
1169 fg
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
1170 old_fg
= x
->foreground_pixel
;
1171 x
->foreground_pixel
= fg
;
1173 if (FRAME_X_WINDOW (f
) != 0)
1175 Display
*dpy
= FRAME_X_DISPLAY (f
);
1178 XSetForeground (dpy
, x
->normal_gc
, fg
);
1179 XSetBackground (dpy
, x
->reverse_gc
, fg
);
1181 if (x
->cursor_pixel
== old_fg
)
1183 unload_color (f
, x
->cursor_pixel
);
1184 x
->cursor_pixel
= x_copy_color (f
, fg
);
1185 XSetBackground (dpy
, x
->cursor_gc
, x
->cursor_pixel
);
1190 update_face_from_frame_parameter (f
, Qforeground_color
, arg
);
1192 if (FRAME_VISIBLE_P (f
))
1196 unload_color (f
, old_fg
);
1200 x_set_background_color (f
, arg
, oldval
)
1202 Lisp_Object arg
, oldval
;
1204 struct x_output
*x
= f
->output_data
.x
;
1207 bg
= x_decode_color (f
, arg
, WHITE_PIX_DEFAULT (f
));
1208 unload_color (f
, x
->background_pixel
);
1209 x
->background_pixel
= bg
;
1211 if (FRAME_X_WINDOW (f
) != 0)
1213 Display
*dpy
= FRAME_X_DISPLAY (f
);
1216 XSetBackground (dpy
, x
->normal_gc
, bg
);
1217 XSetForeground (dpy
, x
->reverse_gc
, bg
);
1218 XSetWindowBackground (dpy
, FRAME_X_WINDOW (f
), bg
);
1219 XSetForeground (dpy
, x
->cursor_gc
, bg
);
1222 xg_set_background_color (f
, bg
);
1225 #ifndef USE_TOOLKIT_SCROLL_BARS /* Turns out to be annoying with
1226 toolkit scroll bars. */
1229 for (bar
= FRAME_SCROLL_BARS (f
);
1231 bar
= XSCROLL_BAR (bar
)->next
)
1233 Window window
= SCROLL_BAR_X_WINDOW (XSCROLL_BAR (bar
));
1234 XSetWindowBackground (dpy
, window
, bg
);
1237 #endif /* USE_TOOLKIT_SCROLL_BARS */
1240 update_face_from_frame_parameter (f
, Qbackground_color
, arg
);
1242 if (FRAME_VISIBLE_P (f
))
1248 x_set_mouse_color (f
, arg
, oldval
)
1250 Lisp_Object arg
, oldval
;
1252 struct x_output
*x
= f
->output_data
.x
;
1253 Display
*dpy
= FRAME_X_DISPLAY (f
);
1254 Cursor cursor
, nontext_cursor
, mode_cursor
, hand_cursor
;
1255 Cursor hourglass_cursor
, horizontal_drag_cursor
;
1257 unsigned long pixel
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
1258 unsigned long mask_color
= x
->background_pixel
;
1260 /* Don't let pointers be invisible. */
1261 if (mask_color
== pixel
)
1263 x_free_colors (f
, &pixel
, 1);
1264 pixel
= x_copy_color (f
, x
->foreground_pixel
);
1267 unload_color (f
, x
->mouse_pixel
);
1268 x
->mouse_pixel
= pixel
;
1272 /* It's not okay to crash if the user selects a screwy cursor. */
1273 count
= x_catch_errors (dpy
);
1275 if (!NILP (Vx_pointer_shape
))
1277 CHECK_NUMBER (Vx_pointer_shape
);
1278 cursor
= XCreateFontCursor (dpy
, XINT (Vx_pointer_shape
));
1281 cursor
= XCreateFontCursor (dpy
, XC_xterm
);
1282 x_check_errors (dpy
, "bad text pointer cursor: %s");
1284 if (!NILP (Vx_nontext_pointer_shape
))
1286 CHECK_NUMBER (Vx_nontext_pointer_shape
);
1288 = XCreateFontCursor (dpy
, XINT (Vx_nontext_pointer_shape
));
1291 nontext_cursor
= XCreateFontCursor (dpy
, XC_left_ptr
);
1292 x_check_errors (dpy
, "bad nontext pointer cursor: %s");
1294 if (!NILP (Vx_hourglass_pointer_shape
))
1296 CHECK_NUMBER (Vx_hourglass_pointer_shape
);
1298 = XCreateFontCursor (dpy
, XINT (Vx_hourglass_pointer_shape
));
1301 hourglass_cursor
= XCreateFontCursor (dpy
, XC_watch
);
1302 x_check_errors (dpy
, "bad hourglass pointer cursor: %s");
1304 if (!NILP (Vx_mode_pointer_shape
))
1306 CHECK_NUMBER (Vx_mode_pointer_shape
);
1307 mode_cursor
= XCreateFontCursor (dpy
, XINT (Vx_mode_pointer_shape
));
1310 mode_cursor
= XCreateFontCursor (dpy
, XC_xterm
);
1311 x_check_errors (dpy
, "bad modeline pointer cursor: %s");
1313 if (!NILP (Vx_sensitive_text_pointer_shape
))
1315 CHECK_NUMBER (Vx_sensitive_text_pointer_shape
);
1317 = XCreateFontCursor (dpy
, XINT (Vx_sensitive_text_pointer_shape
));
1320 hand_cursor
= XCreateFontCursor (dpy
, XC_hand2
);
1322 if (!NILP (Vx_window_horizontal_drag_shape
))
1324 CHECK_NUMBER (Vx_window_horizontal_drag_shape
);
1325 horizontal_drag_cursor
1326 = XCreateFontCursor (dpy
, XINT (Vx_window_horizontal_drag_shape
));
1329 horizontal_drag_cursor
1330 = XCreateFontCursor (dpy
, XC_sb_h_double_arrow
);
1332 /* Check and report errors with the above calls. */
1333 x_check_errors (dpy
, "can't set cursor shape: %s");
1334 x_uncatch_errors (dpy
, count
);
1337 XColor fore_color
, back_color
;
1339 fore_color
.pixel
= x
->mouse_pixel
;
1340 x_query_color (f
, &fore_color
);
1341 back_color
.pixel
= mask_color
;
1342 x_query_color (f
, &back_color
);
1344 XRecolorCursor (dpy
, cursor
, &fore_color
, &back_color
);
1345 XRecolorCursor (dpy
, nontext_cursor
, &fore_color
, &back_color
);
1346 XRecolorCursor (dpy
, mode_cursor
, &fore_color
, &back_color
);
1347 XRecolorCursor (dpy
, hand_cursor
, &fore_color
, &back_color
);
1348 XRecolorCursor (dpy
, hourglass_cursor
, &fore_color
, &back_color
);
1349 XRecolorCursor (dpy
, horizontal_drag_cursor
, &fore_color
, &back_color
);
1352 if (FRAME_X_WINDOW (f
) != 0)
1353 XDefineCursor (dpy
, FRAME_X_WINDOW (f
), cursor
);
1355 if (cursor
!= x
->text_cursor
1356 && x
->text_cursor
!= 0)
1357 XFreeCursor (dpy
, x
->text_cursor
);
1358 x
->text_cursor
= cursor
;
1360 if (nontext_cursor
!= x
->nontext_cursor
1361 && x
->nontext_cursor
!= 0)
1362 XFreeCursor (dpy
, x
->nontext_cursor
);
1363 x
->nontext_cursor
= nontext_cursor
;
1365 if (hourglass_cursor
!= x
->hourglass_cursor
1366 && x
->hourglass_cursor
!= 0)
1367 XFreeCursor (dpy
, x
->hourglass_cursor
);
1368 x
->hourglass_cursor
= hourglass_cursor
;
1370 if (mode_cursor
!= x
->modeline_cursor
1371 && x
->modeline_cursor
!= 0)
1372 XFreeCursor (dpy
, f
->output_data
.x
->modeline_cursor
);
1373 x
->modeline_cursor
= mode_cursor
;
1375 if (hand_cursor
!= x
->hand_cursor
1376 && x
->hand_cursor
!= 0)
1377 XFreeCursor (dpy
, x
->hand_cursor
);
1378 x
->hand_cursor
= hand_cursor
;
1380 if (horizontal_drag_cursor
!= x
->horizontal_drag_cursor
1381 && x
->horizontal_drag_cursor
!= 0)
1382 XFreeCursor (dpy
, x
->horizontal_drag_cursor
);
1383 x
->horizontal_drag_cursor
= horizontal_drag_cursor
;
1388 update_face_from_frame_parameter (f
, Qmouse_color
, arg
);
1392 x_set_cursor_color (f
, arg
, oldval
)
1394 Lisp_Object arg
, oldval
;
1396 unsigned long fore_pixel
, pixel
;
1397 int fore_pixel_allocated_p
= 0, pixel_allocated_p
= 0;
1398 struct x_output
*x
= f
->output_data
.x
;
1400 if (!NILP (Vx_cursor_fore_pixel
))
1402 fore_pixel
= x_decode_color (f
, Vx_cursor_fore_pixel
,
1403 WHITE_PIX_DEFAULT (f
));
1404 fore_pixel_allocated_p
= 1;
1407 fore_pixel
= x
->background_pixel
;
1409 pixel
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
1410 pixel_allocated_p
= 1;
1412 /* Make sure that the cursor color differs from the background color. */
1413 if (pixel
== x
->background_pixel
)
1415 if (pixel_allocated_p
)
1417 x_free_colors (f
, &pixel
, 1);
1418 pixel_allocated_p
= 0;
1421 pixel
= x
->mouse_pixel
;
1422 if (pixel
== fore_pixel
)
1424 if (fore_pixel_allocated_p
)
1426 x_free_colors (f
, &fore_pixel
, 1);
1427 fore_pixel_allocated_p
= 0;
1429 fore_pixel
= x
->background_pixel
;
1433 unload_color (f
, x
->cursor_foreground_pixel
);
1434 if (!fore_pixel_allocated_p
)
1435 fore_pixel
= x_copy_color (f
, fore_pixel
);
1436 x
->cursor_foreground_pixel
= fore_pixel
;
1438 unload_color (f
, x
->cursor_pixel
);
1439 if (!pixel_allocated_p
)
1440 pixel
= x_copy_color (f
, pixel
);
1441 x
->cursor_pixel
= pixel
;
1443 if (FRAME_X_WINDOW (f
) != 0)
1446 XSetBackground (FRAME_X_DISPLAY (f
), x
->cursor_gc
, x
->cursor_pixel
);
1447 XSetForeground (FRAME_X_DISPLAY (f
), x
->cursor_gc
, fore_pixel
);
1450 if (FRAME_VISIBLE_P (f
))
1452 x_update_cursor (f
, 0);
1453 x_update_cursor (f
, 1);
1457 update_face_from_frame_parameter (f
, Qcursor_color
, arg
);
1460 /* Set the border-color of frame F to pixel value PIX.
1461 Note that this does not fully take effect if done before
1462 F has an x-window. */
1465 x_set_border_pixel (f
, pix
)
1469 unload_color (f
, f
->output_data
.x
->border_pixel
);
1470 f
->output_data
.x
->border_pixel
= pix
;
1472 if (FRAME_X_WINDOW (f
) != 0 && f
->border_width
> 0)
1475 XSetWindowBorder (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
1476 (unsigned long)pix
);
1479 if (FRAME_VISIBLE_P (f
))
1484 /* Set the border-color of frame F to value described by ARG.
1485 ARG can be a string naming a color.
1486 The border-color is used for the border that is drawn by the X server.
1487 Note that this does not fully take effect if done before
1488 F has an x-window; it must be redone when the window is created.
1490 Note: this is done in two routines because of the way X10 works.
1492 Note: under X11, this is normally the province of the window manager,
1493 and so emacs' border colors may be overridden. */
1496 x_set_border_color (f
, arg
, oldval
)
1498 Lisp_Object arg
, oldval
;
1503 pix
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
1504 x_set_border_pixel (f
, pix
);
1505 update_face_from_frame_parameter (f
, Qborder_color
, arg
);
1510 x_set_cursor_type (f
, arg
, oldval
)
1512 Lisp_Object arg
, oldval
;
1514 set_frame_cursor_types (f
, arg
);
1516 /* Make sure the cursor gets redrawn. */
1517 cursor_type_changed
= 1;
1521 x_set_icon_type (f
, arg
, oldval
)
1523 Lisp_Object arg
, oldval
;
1529 if (STRINGP (oldval
) && EQ (Fstring_equal (oldval
, arg
), Qt
))
1532 else if (!STRINGP (oldval
) && EQ (oldval
, Qnil
) == EQ (arg
, Qnil
))
1537 result
= x_text_icon (f
,
1538 (char *) SDATA ((!NILP (f
->icon_name
)
1542 result
= x_bitmap_icon (f
, arg
);
1547 error ("No icon window available");
1550 XFlush (FRAME_X_DISPLAY (f
));
1555 x_set_icon_name (f
, arg
, oldval
)
1557 Lisp_Object arg
, oldval
;
1563 if (STRINGP (oldval
) && EQ (Fstring_equal (oldval
, arg
), Qt
))
1566 else if (!STRINGP (oldval
) && EQ (oldval
, Qnil
) == EQ (arg
, Qnil
))
1571 if (f
->output_data
.x
->icon_bitmap
!= 0)
1576 result
= x_text_icon (f
,
1577 (char *) SDATA ((!NILP (f
->icon_name
)
1586 error ("No icon window available");
1589 XFlush (FRAME_X_DISPLAY (f
));
1595 x_set_menu_bar_lines (f
, value
, oldval
)
1597 Lisp_Object value
, oldval
;
1600 #ifndef USE_X_TOOLKIT
1601 int olines
= FRAME_MENU_BAR_LINES (f
);
1604 /* Right now, menu bars don't work properly in minibuf-only frames;
1605 most of the commands try to apply themselves to the minibuffer
1606 frame itself, and get an error because you can't switch buffers
1607 in or split the minibuffer window. */
1608 if (FRAME_MINIBUF_ONLY_P (f
))
1611 if (INTEGERP (value
))
1612 nlines
= XINT (value
);
1616 /* Make sure we redisplay all windows in this frame. */
1617 windows_or_buffers_changed
++;
1619 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
1620 FRAME_MENU_BAR_LINES (f
) = 0;
1623 FRAME_EXTERNAL_MENU_BAR (f
) = 1;
1624 if (FRAME_X_P (f
) && f
->output_data
.x
->menubar_widget
== 0)
1625 /* Make sure next redisplay shows the menu bar. */
1626 XWINDOW (FRAME_SELECTED_WINDOW (f
))->update_mode_line
= Qt
;
1630 if (FRAME_EXTERNAL_MENU_BAR (f
) == 1)
1631 free_frame_menubar (f
);
1632 FRAME_EXTERNAL_MENU_BAR (f
) = 0;
1634 f
->output_data
.x
->menubar_widget
= 0;
1636 #else /* not USE_X_TOOLKIT && not USE_GTK */
1637 FRAME_MENU_BAR_LINES (f
) = nlines
;
1638 change_window_heights (f
->root_window
, nlines
- olines
);
1639 #endif /* not USE_X_TOOLKIT */
1644 /* Set the number of lines used for the tool bar of frame F to VALUE.
1645 VALUE not an integer, or < 0 means set the lines to zero. OLDVAL
1646 is the old number of tool bar lines. This function changes the
1647 height of all windows on frame F to match the new tool bar height.
1648 The frame's height doesn't change. */
1651 x_set_tool_bar_lines (f
, value
, oldval
)
1653 Lisp_Object value
, oldval
;
1655 int delta
, nlines
, root_height
;
1656 Lisp_Object root_window
;
1658 /* Treat tool bars like menu bars. */
1659 if (FRAME_MINIBUF_ONLY_P (f
))
1662 /* Use VALUE only if an integer >= 0. */
1663 if (INTEGERP (value
) && XINT (value
) >= 0)
1664 nlines
= XFASTINT (value
);
1669 FRAME_TOOL_BAR_LINES (f
) = 0;
1672 FRAME_EXTERNAL_TOOL_BAR (f
) = 1;
1673 if (FRAME_X_P (f
) && f
->output_data
.x
->toolbar_widget
== 0)
1674 /* Make sure next redisplay shows the tool bar. */
1675 XWINDOW (FRAME_SELECTED_WINDOW (f
))->update_mode_line
= Qt
;
1676 update_frame_tool_bar (f
);
1680 if (FRAME_EXTERNAL_TOOL_BAR (f
))
1681 free_frame_tool_bar (f
);
1682 FRAME_EXTERNAL_TOOL_BAR (f
) = 0;
1688 /* Make sure we redisplay all windows in this frame. */
1689 ++windows_or_buffers_changed
;
1691 delta
= nlines
- FRAME_TOOL_BAR_LINES (f
);
1693 /* Don't resize the tool-bar to more than we have room for. */
1694 root_window
= FRAME_ROOT_WINDOW (f
);
1695 root_height
= WINDOW_TOTAL_LINES (XWINDOW (root_window
));
1696 if (root_height
- delta
< 1)
1698 delta
= root_height
- 1;
1699 nlines
= FRAME_TOOL_BAR_LINES (f
) + delta
;
1702 FRAME_TOOL_BAR_LINES (f
) = nlines
;
1703 change_window_heights (root_window
, delta
);
1706 /* We also have to make sure that the internal border at the top of
1707 the frame, below the menu bar or tool bar, is redrawn when the
1708 tool bar disappears. This is so because the internal border is
1709 below the tool bar if one is displayed, but is below the menu bar
1710 if there isn't a tool bar. The tool bar draws into the area
1711 below the menu bar. */
1712 if (FRAME_X_WINDOW (f
) && FRAME_TOOL_BAR_LINES (f
) == 0)
1716 clear_current_matrices (f
);
1717 updating_frame
= NULL
;
1720 /* If the tool bar gets smaller, the internal border below it
1721 has to be cleared. It was formerly part of the display
1722 of the larger tool bar, and updating windows won't clear it. */
1725 int height
= FRAME_INTERNAL_BORDER_WIDTH (f
);
1726 int width
= FRAME_PIXEL_WIDTH (f
);
1727 int y
= nlines
* FRAME_LINE_HEIGHT (f
);
1730 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
1731 0, y
, width
, height
, False
);
1734 if (WINDOWP (f
->tool_bar_window
))
1735 clear_glyph_matrix (XWINDOW (f
->tool_bar_window
)->current_matrix
);
1740 /* Set the foreground color for scroll bars on frame F to VALUE.
1741 VALUE should be a string, a color name. If it isn't a string or
1742 isn't a valid color name, do nothing. OLDVAL is the old value of
1743 the frame parameter. */
1746 x_set_scroll_bar_foreground (f
, value
, oldval
)
1748 Lisp_Object value
, oldval
;
1750 unsigned long pixel
;
1752 if (STRINGP (value
))
1753 pixel
= x_decode_color (f
, value
, BLACK_PIX_DEFAULT (f
));
1757 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
1758 unload_color (f
, f
->output_data
.x
->scroll_bar_foreground_pixel
);
1760 f
->output_data
.x
->scroll_bar_foreground_pixel
= pixel
;
1761 if (FRAME_X_WINDOW (f
) && FRAME_VISIBLE_P (f
))
1763 /* Remove all scroll bars because they have wrong colors. */
1764 if (FRAME_DISPLAY (f
)->condemn_scroll_bars_hook
)
1765 (*FRAME_DISPLAY (f
)->condemn_scroll_bars_hook
) (f
);
1766 if (FRAME_DISPLAY (f
)->judge_scroll_bars_hook
)
1767 (*FRAME_DISPLAY (f
)->judge_scroll_bars_hook
) (f
);
1769 update_face_from_frame_parameter (f
, Qscroll_bar_foreground
, value
);
1775 /* Set the background color for scroll bars on frame F to VALUE VALUE
1776 should be a string, a color name. If it isn't a string or isn't a
1777 valid color name, do nothing. OLDVAL is the old value of the frame
1781 x_set_scroll_bar_background (f
, value
, oldval
)
1783 Lisp_Object value
, oldval
;
1785 unsigned long pixel
;
1787 if (STRINGP (value
))
1788 pixel
= x_decode_color (f
, value
, WHITE_PIX_DEFAULT (f
));
1792 if (f
->output_data
.x
->scroll_bar_background_pixel
!= -1)
1793 unload_color (f
, f
->output_data
.x
->scroll_bar_background_pixel
);
1795 #ifdef USE_TOOLKIT_SCROLL_BARS
1796 /* Scrollbar shadow colors. */
1797 if (f
->output_data
.x
->scroll_bar_top_shadow_pixel
!= -1)
1799 unload_color (f
, f
->output_data
.x
->scroll_bar_top_shadow_pixel
);
1800 f
->output_data
.x
->scroll_bar_top_shadow_pixel
= -1;
1802 if (f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
!= -1)
1804 unload_color (f
, f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
);
1805 f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
= -1;
1807 #endif /* USE_TOOLKIT_SCROLL_BARS */
1809 f
->output_data
.x
->scroll_bar_background_pixel
= pixel
;
1810 if (FRAME_X_WINDOW (f
) && FRAME_VISIBLE_P (f
))
1812 /* Remove all scroll bars because they have wrong colors. */
1813 if (FRAME_DISPLAY (f
)->condemn_scroll_bars_hook
)
1814 (*FRAME_DISPLAY (f
)->condemn_scroll_bars_hook
) (f
);
1815 if (FRAME_DISPLAY (f
)->judge_scroll_bars_hook
)
1816 (*FRAME_DISPLAY (f
)->judge_scroll_bars_hook
) (f
);
1818 update_face_from_frame_parameter (f
, Qscroll_bar_background
, value
);
1824 /* Encode Lisp string STRING as a text in a format appropriate for
1825 XICCC (X Inter Client Communication Conventions).
1827 If STRING contains only ASCII characters, do no conversion and
1828 return the string data of STRING. Otherwise, encode the text by
1829 CODING_SYSTEM, and return a newly allocated memory area which
1830 should be freed by `xfree' by a caller.
1832 SELECTIONP non-zero means the string is being encoded for an X
1833 selection, so it is safe to run pre-write conversions (which
1836 Store the byte length of resulting text in *TEXT_BYTES.
1838 If the text contains only ASCII and Latin-1, store 1 in *STRING_P,
1839 which means that the `encoding' of the result can be `STRING'.
1840 Otherwise store 0 in *STRINGP, which means that the `encoding' of
1841 the result should be `COMPOUND_TEXT'. */
1844 x_encode_text (string
, coding_system
, selectionp
, text_bytes
, stringp
)
1845 Lisp_Object string
, coding_system
;
1846 int *text_bytes
, *stringp
;
1849 unsigned char *str
= SDATA (string
);
1850 int chars
= SCHARS (string
);
1851 int bytes
= SBYTES (string
);
1855 struct coding_system coding
;
1856 extern Lisp_Object Qcompound_text_with_extensions
;
1858 charset_info
= find_charset_in_text (str
, chars
, bytes
, NULL
, Qnil
);
1859 if (charset_info
== 0)
1861 /* No multibyte character in OBJ. We need not encode it. */
1862 *text_bytes
= bytes
;
1867 setup_coding_system (coding_system
, &coding
);
1869 && SYMBOLP (coding
.pre_write_conversion
)
1870 && !NILP (Ffboundp (coding
.pre_write_conversion
)))
1872 string
= run_pre_post_conversion_on_str (string
, &coding
, 1);
1873 str
= SDATA (string
);
1874 chars
= SCHARS (string
);
1875 bytes
= SBYTES (string
);
1877 coding
.src_multibyte
= 1;
1878 coding
.dst_multibyte
= 0;
1879 coding
.mode
|= CODING_MODE_LAST_BLOCK
;
1880 if (coding
.type
== coding_type_iso2022
)
1881 coding
.flags
|= CODING_FLAG_ISO_SAFE
;
1882 /* We suppress producing escape sequences for composition. */
1883 coding
.composing
= COMPOSITION_DISABLED
;
1884 bufsize
= encoding_buffer_size (&coding
, bytes
);
1885 buf
= (unsigned char *) xmalloc (bufsize
);
1886 encode_coding (&coding
, str
, buf
, bytes
, bufsize
);
1887 *text_bytes
= coding
.produced
;
1888 *stringp
= (charset_info
== 1
1889 || (!EQ (coding_system
, Qcompound_text
)
1890 && !EQ (coding_system
, Qcompound_text_with_extensions
)));
1895 /* Change the name of frame F to NAME. If NAME is nil, set F's name to
1898 If EXPLICIT is non-zero, that indicates that lisp code is setting the
1899 name; if NAME is a string, set F's name to NAME and set
1900 F->explicit_name; if NAME is Qnil, then clear F->explicit_name.
1902 If EXPLICIT is zero, that indicates that Emacs redisplay code is
1903 suggesting a new name, which lisp code should override; if
1904 F->explicit_name is set, ignore the new name; otherwise, set it. */
1907 x_set_name (f
, name
, explicit)
1912 /* Make sure that requests from lisp code override requests from
1913 Emacs redisplay code. */
1916 /* If we're switching from explicit to implicit, we had better
1917 update the mode lines and thereby update the title. */
1918 if (f
->explicit_name
&& NILP (name
))
1919 update_mode_lines
= 1;
1921 f
->explicit_name
= ! NILP (name
);
1923 else if (f
->explicit_name
)
1926 /* If NAME is nil, set the name to the x_id_name. */
1929 /* Check for no change needed in this very common case
1930 before we do any consing. */
1931 if (!strcmp (FRAME_X_DISPLAY_INFO (f
)->x_id_name
,
1934 name
= build_string (FRAME_X_DISPLAY_INFO (f
)->x_id_name
);
1937 CHECK_STRING (name
);
1939 /* Don't change the name if it's already NAME. */
1940 if (! NILP (Fstring_equal (name
, f
->name
)))
1945 /* For setting the frame title, the title parameter should override
1946 the name parameter. */
1947 if (! NILP (f
->title
))
1950 if (FRAME_X_WINDOW (f
))
1955 XTextProperty text
, icon
;
1957 Lisp_Object coding_system
;
1959 /* Note: Encoding strategy
1961 We encode NAME by compound-text and use "COMPOUND-TEXT" in
1962 text.encoding. But, there are non-internationalized window
1963 managers which don't support that encoding. So, if NAME
1964 contains only ASCII and 8859-1 characters, encode it by
1965 iso-latin-1, and use "STRING" in text.encoding hoping that
1966 such window managers at least analyze this format correctly,
1967 i.e. treat 8-bit bytes as 8859-1 characters.
1969 We may also be able to use "UTF8_STRING" in text.encoding
1970 in the future which can encode all Unicode characters.
1971 But, for the moment, there's no way to know that the
1972 current window manager supports it or not. */
1973 coding_system
= Qcompound_text
;
1974 text
.value
= x_encode_text (name
, coding_system
, 0, &bytes
, &stringp
);
1975 text
.encoding
= (stringp
? XA_STRING
1976 : FRAME_X_DISPLAY_INFO (f
)->Xatom_COMPOUND_TEXT
);
1978 text
.nitems
= bytes
;
1980 if (NILP (f
->icon_name
))
1986 /* See the above comment "Note: Encoding strategy". */
1987 icon
.value
= x_encode_text (f
->icon_name
, coding_system
, 0,
1989 icon
.encoding
= (stringp
? XA_STRING
1990 : FRAME_X_DISPLAY_INFO (f
)->Xatom_COMPOUND_TEXT
);
1992 icon
.nitems
= bytes
;
1995 gtk_window_set_title (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f
)),
1997 #else /* not USE_GTK */
1998 XSetWMName (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
), &text
);
1999 #endif /* not USE_GTK */
2001 XSetWMIconName (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
), &icon
);
2003 if (!NILP (f
->icon_name
)
2004 && icon
.value
!= (unsigned char *) SDATA (f
->icon_name
))
2006 if (text
.value
!= (unsigned char *) SDATA (name
))
2009 #else /* not HAVE_X11R4 */
2010 XSetIconName (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2012 XStoreName (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2014 #endif /* not HAVE_X11R4 */
2019 /* This function should be called when the user's lisp code has
2020 specified a name for the frame; the name will override any set by the
2023 x_explicitly_set_name (f
, arg
, oldval
)
2025 Lisp_Object arg
, oldval
;
2027 x_set_name (f
, arg
, 1);
2030 /* This function should be called by Emacs redisplay code to set the
2031 name; names set this way will never override names set by the user's
2034 x_implicitly_set_name (f
, arg
, oldval
)
2036 Lisp_Object arg
, oldval
;
2038 x_set_name (f
, arg
, 0);
2041 /* Change the title of frame F to NAME.
2042 If NAME is nil, use the frame name as the title.
2044 If EXPLICIT is non-zero, that indicates that lisp code is setting the
2045 name; if NAME is a string, set F's name to NAME and set
2046 F->explicit_name; if NAME is Qnil, then clear F->explicit_name.
2048 If EXPLICIT is zero, that indicates that Emacs redisplay code is
2049 suggesting a new name, which lisp code should override; if
2050 F->explicit_name is set, ignore the new name; otherwise, set it. */
2053 x_set_title (f
, name
, old_name
)
2055 Lisp_Object name
, old_name
;
2057 /* Don't change the title if it's already NAME. */
2058 if (EQ (name
, f
->title
))
2061 update_mode_lines
= 1;
2068 CHECK_STRING (name
);
2070 if (FRAME_X_WINDOW (f
))
2075 XTextProperty text
, icon
;
2077 Lisp_Object coding_system
;
2079 coding_system
= Qcompound_text
;
2080 /* See the comment "Note: Encoding strategy" in x_set_name. */
2081 text
.value
= x_encode_text (name
, coding_system
, 0, &bytes
, &stringp
);
2082 text
.encoding
= (stringp
? XA_STRING
2083 : FRAME_X_DISPLAY_INFO (f
)->Xatom_COMPOUND_TEXT
);
2085 text
.nitems
= bytes
;
2087 if (NILP (f
->icon_name
))
2093 /* See the comment "Note: Encoding strategy" in x_set_name. */
2094 icon
.value
= x_encode_text (f
->icon_name
, coding_system
, 0,
2096 icon
.encoding
= (stringp
? XA_STRING
2097 : FRAME_X_DISPLAY_INFO (f
)->Xatom_COMPOUND_TEXT
);
2099 icon
.nitems
= bytes
;
2103 gtk_window_set_title (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f
)),
2105 #else /* not USE_GTK */
2106 XSetWMName (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
), &text
);
2107 #endif /* not USE_GTK */
2109 XSetWMIconName (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
2112 if (!NILP (f
->icon_name
)
2113 && icon
.value
!= (unsigned char *) SDATA (f
->icon_name
))
2115 if (text
.value
!= (unsigned char *) SDATA (name
))
2118 #else /* not HAVE_X11R4 */
2119 XSetIconName (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2121 XStoreName (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2123 #endif /* not HAVE_X11R4 */
2129 x_set_scroll_bar_default_width (f
)
2132 int wid
= FRAME_COLUMN_WIDTH (f
);
2134 #ifdef USE_TOOLKIT_SCROLL_BARS
2135 /* A minimum width of 14 doesn't look good for toolkit scroll bars. */
2136 int width
= 16 + 2 * VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
2137 FRAME_CONFIG_SCROLL_BAR_COLS (f
) = (width
+ wid
- 1) / wid
;
2138 FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) = width
;
2140 /* Make the actual width at least 14 pixels and a multiple of a
2142 FRAME_CONFIG_SCROLL_BAR_COLS (f
) = (14 + wid
- 1) / wid
;
2144 /* Use all of that space (aside from required margins) for the
2146 FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) = 0;
2151 /* Record in frame F the specified or default value according to ALIST
2152 of the parameter named PROP (a Lisp symbol). If no value is
2153 specified for PROP, look for an X default for XPROP on the frame
2154 named NAME. If that is not found either, use the value DEFLT. */
2157 x_default_scroll_bar_color_parameter (f
, alist
, prop
, xprop
, xclass
,
2166 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
2169 tem
= x_get_arg (dpyinfo
, alist
, prop
, xprop
, xclass
, RES_TYPE_STRING
);
2170 if (EQ (tem
, Qunbound
))
2172 #ifdef USE_TOOLKIT_SCROLL_BARS
2174 /* See if an X resource for the scroll bar color has been
2176 tem
= display_x_get_resource (dpyinfo
,
2177 build_string (foreground_p
2181 build_string ("verticalScrollBar"),
2185 /* If nothing has been specified, scroll bars will use a
2186 toolkit-dependent default. Because these defaults are
2187 difficult to get at without actually creating a scroll
2188 bar, use nil to indicate that no color has been
2193 #else /* not USE_TOOLKIT_SCROLL_BARS */
2197 #endif /* not USE_TOOLKIT_SCROLL_BARS */
2200 x_set_frame_parameters (f
, Fcons (Fcons (prop
, tem
), Qnil
));
2206 #if !defined (HAVE_X11R4) && !defined (HAVE_XSETWMPROTOCOLS)
2209 XSetWMProtocols (dpy
, w
, protocols
, count
)
2216 prop
= XInternAtom (dpy
, "WM_PROTOCOLS", False
);
2217 if (prop
== None
) return False
;
2218 XChangeProperty (dpy
, w
, prop
, XA_ATOM
, 32, PropModeReplace
,
2219 (unsigned char *) protocols
, count
);
2222 #endif /* not HAVE_X11R4 && not HAVE_XSETWMPROTOCOLS */
2224 #ifdef USE_X_TOOLKIT
2226 /* If the WM_PROTOCOLS property does not already contain WM_TAKE_FOCUS,
2227 WM_DELETE_WINDOW, and WM_SAVE_YOURSELF, then add them. (They may
2228 already be present because of the toolkit (Motif adds some of them,
2229 for example, but Xt doesn't). */
2232 hack_wm_protocols (f
, widget
)
2236 Display
*dpy
= XtDisplay (widget
);
2237 Window w
= XtWindow (widget
);
2238 int need_delete
= 1;
2244 Atom type
, *atoms
= 0;
2246 unsigned long nitems
= 0;
2247 unsigned long bytes_after
;
2249 if ((XGetWindowProperty (dpy
, w
,
2250 FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_protocols
,
2251 (long)0, (long)100, False
, XA_ATOM
,
2252 &type
, &format
, &nitems
, &bytes_after
,
2253 (unsigned char **) &atoms
)
2255 && format
== 32 && type
== XA_ATOM
)
2259 if (atoms
[nitems
] == FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_delete_window
)
2261 else if (atoms
[nitems
] == FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_take_focus
)
2263 else if (atoms
[nitems
] == FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_save_yourself
)
2266 if (atoms
) XFree ((char *) atoms
);
2272 props
[count
++] = FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_delete_window
;
2274 props
[count
++] = FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_take_focus
;
2276 props
[count
++] = FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_save_yourself
;
2278 XChangeProperty (dpy
, w
, FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_protocols
,
2279 XA_ATOM
, 32, PropModeAppend
,
2280 (unsigned char *) props
, count
);
2288 /* Support routines for XIC (X Input Context). */
2292 static XFontSet xic_create_xfontset
P_ ((struct frame
*, char *));
2293 static XIMStyle best_xim_style
P_ ((XIMStyles
*, XIMStyles
*));
2296 /* Supported XIM styles, ordered by preference. */
2298 static XIMStyle supported_xim_styles
[] =
2300 XIMPreeditPosition
| XIMStatusArea
,
2301 XIMPreeditPosition
| XIMStatusNothing
,
2302 XIMPreeditPosition
| XIMStatusNone
,
2303 XIMPreeditNothing
| XIMStatusArea
,
2304 XIMPreeditNothing
| XIMStatusNothing
,
2305 XIMPreeditNothing
| XIMStatusNone
,
2306 XIMPreeditNone
| XIMStatusArea
,
2307 XIMPreeditNone
| XIMStatusNothing
,
2308 XIMPreeditNone
| XIMStatusNone
,
2313 /* Create an X fontset on frame F with base font name
2317 xic_create_xfontset (f
, base_fontname
)
2319 char *base_fontname
;
2322 char **missing_list
;
2326 xfs
= XCreateFontSet (FRAME_X_DISPLAY (f
),
2327 base_fontname
, &missing_list
,
2328 &missing_count
, &def_string
);
2330 XFreeStringList (missing_list
);
2332 /* No need to free def_string. */
2337 /* Value is the best input style, given user preferences USER (already
2338 checked to be supported by Emacs), and styles supported by the
2339 input method XIM. */
2342 best_xim_style (user
, xim
)
2348 for (i
= 0; i
< user
->count_styles
; ++i
)
2349 for (j
= 0; j
< xim
->count_styles
; ++j
)
2350 if (user
->supported_styles
[i
] == xim
->supported_styles
[j
])
2351 return user
->supported_styles
[i
];
2353 /* Return the default style. */
2354 return XIMPreeditNothing
| XIMStatusNothing
;
2357 /* Create XIC for frame F. */
2359 static XIMStyle xic_style
;
2362 create_frame_xic (f
)
2367 XFontSet xfs
= NULL
;
2372 xim
= FRAME_X_XIM (f
);
2377 XVaNestedList preedit_attr
;
2378 XVaNestedList status_attr
;
2379 char *base_fontname
;
2382 s_area
.x
= 0; s_area
.y
= 0; s_area
.width
= 1; s_area
.height
= 1;
2383 spot
.x
= 0; spot
.y
= 1;
2384 /* Create X fontset. */
2385 fontset
= FRAME_FONTSET (f
);
2387 base_fontname
= "-*-*-*-r-normal--14-*-*-*-*-*-*-*";
2390 /* Determine the base fontname from the ASCII font name of
2392 char *ascii_font
= (char *) SDATA (fontset_ascii (fontset
));
2393 char *p
= ascii_font
;
2396 for (i
= 0; *p
; p
++)
2399 /* As the font name doesn't conform to XLFD, we can't
2400 modify it to get a suitable base fontname for the
2402 base_fontname
= "-*-*-*-r-normal--14-*-*-*-*-*-*-*";
2405 int len
= strlen (ascii_font
) + 1;
2408 for (i
= 0, p
= ascii_font
; i
< 8; p
++)
2417 base_fontname
= (char *) alloca (len
);
2418 bzero (base_fontname
, len
);
2419 strcpy (base_fontname
, "-*-*-");
2420 bcopy (p1
, base_fontname
+ 5, p
- p1
);
2421 strcat (base_fontname
, "*-*-*-*-*-*-*");
2424 xfs
= xic_create_xfontset (f
, base_fontname
);
2426 /* Determine XIC style. */
2429 XIMStyles supported_list
;
2430 supported_list
.count_styles
= (sizeof supported_xim_styles
2431 / sizeof supported_xim_styles
[0]);
2432 supported_list
.supported_styles
= supported_xim_styles
;
2433 xic_style
= best_xim_style (&supported_list
,
2434 FRAME_X_XIM_STYLES (f
));
2437 preedit_attr
= XVaCreateNestedList (0,
2440 FRAME_FOREGROUND_PIXEL (f
),
2442 FRAME_BACKGROUND_PIXEL (f
),
2443 (xic_style
& XIMPreeditPosition
2448 status_attr
= XVaCreateNestedList (0,
2454 FRAME_FOREGROUND_PIXEL (f
),
2456 FRAME_BACKGROUND_PIXEL (f
),
2459 xic
= XCreateIC (xim
,
2460 XNInputStyle
, xic_style
,
2461 XNClientWindow
, FRAME_X_WINDOW (f
),
2462 XNFocusWindow
, FRAME_X_WINDOW (f
),
2463 XNStatusAttributes
, status_attr
,
2464 XNPreeditAttributes
, preedit_attr
,
2466 XFree (preedit_attr
);
2467 XFree (status_attr
);
2470 FRAME_XIC (f
) = xic
;
2471 FRAME_XIC_STYLE (f
) = xic_style
;
2472 FRAME_XIC_FONTSET (f
) = xfs
;
2476 /* Destroy XIC and free XIC fontset of frame F, if any. */
2482 if (FRAME_XIC (f
) == NULL
)
2485 XDestroyIC (FRAME_XIC (f
));
2486 if (FRAME_XIC_FONTSET (f
))
2487 XFreeFontSet (FRAME_X_DISPLAY (f
), FRAME_XIC_FONTSET (f
));
2489 FRAME_XIC (f
) = NULL
;
2490 FRAME_XIC_FONTSET (f
) = NULL
;
2494 /* Place preedit area for XIC of window W's frame to specified
2495 pixel position X/Y. X and Y are relative to window W. */
2498 xic_set_preeditarea (w
, x
, y
)
2502 struct frame
*f
= XFRAME (w
->frame
);
2506 spot
.x
= WINDOW_TO_FRAME_PIXEL_X (w
, x
) + WINDOW_LEFT_FRINGE_WIDTH (w
);
2507 spot
.y
= WINDOW_TO_FRAME_PIXEL_Y (w
, y
) + FONT_BASE (FRAME_FONT (f
));
2508 attr
= XVaCreateNestedList (0, XNSpotLocation
, &spot
, NULL
);
2509 XSetICValues (FRAME_XIC (f
), XNPreeditAttributes
, attr
, NULL
);
2514 /* Place status area for XIC in bottom right corner of frame F.. */
2517 xic_set_statusarea (f
)
2520 XIC xic
= FRAME_XIC (f
);
2525 /* Negotiate geometry of status area. If input method has existing
2526 status area, use its current size. */
2527 area
.x
= area
.y
= area
.width
= area
.height
= 0;
2528 attr
= XVaCreateNestedList (0, XNAreaNeeded
, &area
, NULL
);
2529 XSetICValues (xic
, XNStatusAttributes
, attr
, NULL
);
2532 attr
= XVaCreateNestedList (0, XNAreaNeeded
, &needed
, NULL
);
2533 XGetICValues (xic
, XNStatusAttributes
, attr
, NULL
);
2536 if (needed
->width
== 0) /* Use XNArea instead of XNAreaNeeded */
2538 attr
= XVaCreateNestedList (0, XNArea
, &needed
, NULL
);
2539 XGetICValues (xic
, XNStatusAttributes
, attr
, NULL
);
2543 area
.width
= needed
->width
;
2544 area
.height
= needed
->height
;
2545 area
.x
= FRAME_PIXEL_WIDTH (f
) - area
.width
- FRAME_INTERNAL_BORDER_WIDTH (f
);
2546 area
.y
= (FRAME_PIXEL_HEIGHT (f
) - area
.height
2547 - FRAME_MENUBAR_HEIGHT (f
)
2548 - FRAME_TOOLBAR_HEIGHT (f
)
2549 - FRAME_INTERNAL_BORDER_WIDTH (f
));
2552 attr
= XVaCreateNestedList (0, XNArea
, &area
, NULL
);
2553 XSetICValues (xic
, XNStatusAttributes
, attr
, NULL
);
2558 /* Set X fontset for XIC of frame F, using base font name
2559 BASE_FONTNAME. Called when a new Emacs fontset is chosen. */
2562 xic_set_xfontset (f
, base_fontname
)
2564 char *base_fontname
;
2569 xfs
= xic_create_xfontset (f
, base_fontname
);
2571 attr
= XVaCreateNestedList (0, XNFontSet
, xfs
, NULL
);
2572 if (FRAME_XIC_STYLE (f
) & XIMPreeditPosition
)
2573 XSetICValues (FRAME_XIC (f
), XNPreeditAttributes
, attr
, NULL
);
2574 if (FRAME_XIC_STYLE (f
) & XIMStatusArea
)
2575 XSetICValues (FRAME_XIC (f
), XNStatusAttributes
, attr
, NULL
);
2578 if (FRAME_XIC_FONTSET (f
))
2579 XFreeFontSet (FRAME_X_DISPLAY (f
), FRAME_XIC_FONTSET (f
));
2580 FRAME_XIC_FONTSET (f
) = xfs
;
2583 #endif /* HAVE_X_I18N */
2587 #ifdef USE_X_TOOLKIT
2589 /* Create and set up the X widget for frame F. */
2592 x_window (f
, window_prompting
, minibuffer_only
)
2594 long window_prompting
;
2595 int minibuffer_only
;
2597 XClassHint class_hints
;
2598 XSetWindowAttributes attributes
;
2599 unsigned long attribute_mask
;
2600 Widget shell_widget
;
2602 Widget frame_widget
;
2608 /* Use the resource name as the top-level widget name
2609 for looking up resources. Make a non-Lisp copy
2610 for the window manager, so GC relocation won't bother it.
2612 Elsewhere we specify the window name for the window manager. */
2615 char *str
= (char *) SDATA (Vx_resource_name
);
2616 f
->namebuf
= (char *) xmalloc (strlen (str
) + 1);
2617 strcpy (f
->namebuf
, str
);
2621 XtSetArg (al
[ac
], XtNallowShellResize
, 1); ac
++;
2622 XtSetArg (al
[ac
], XtNinput
, 1); ac
++;
2623 XtSetArg (al
[ac
], XtNmappedWhenManaged
, 0); ac
++;
2624 XtSetArg (al
[ac
], XtNborderWidth
, f
->border_width
); ac
++;
2625 XtSetArg (al
[ac
], XtNvisual
, FRAME_X_VISUAL (f
)); ac
++;
2626 XtSetArg (al
[ac
], XtNdepth
, FRAME_X_DISPLAY_INFO (f
)->n_planes
); ac
++;
2627 XtSetArg (al
[ac
], XtNcolormap
, FRAME_X_COLORMAP (f
)); ac
++;
2628 shell_widget
= XtAppCreateShell (f
->namebuf
, EMACS_CLASS
,
2629 applicationShellWidgetClass
,
2630 FRAME_X_DISPLAY (f
), al
, ac
);
2632 f
->output_data
.x
->widget
= shell_widget
;
2633 /* maybe_set_screen_title_format (shell_widget); */
2635 pane_widget
= lw_create_widget ("main", "pane", widget_id_tick
++,
2636 (widget_value
*) NULL
,
2637 shell_widget
, False
,
2641 (lw_callback
) NULL
);
2644 XtSetArg (al
[ac
], XtNvisual
, FRAME_X_VISUAL (f
)); ac
++;
2645 XtSetArg (al
[ac
], XtNdepth
, FRAME_X_DISPLAY_INFO (f
)->n_planes
); ac
++;
2646 XtSetArg (al
[ac
], XtNcolormap
, FRAME_X_COLORMAP (f
)); ac
++;
2647 XtSetValues (pane_widget
, al
, ac
);
2648 f
->output_data
.x
->column_widget
= pane_widget
;
2650 /* mappedWhenManaged to false tells to the paned window to not map/unmap
2651 the emacs screen when changing menubar. This reduces flickering. */
2654 XtSetArg (al
[ac
], XtNmappedWhenManaged
, 0); ac
++;
2655 XtSetArg (al
[ac
], XtNshowGrip
, 0); ac
++;
2656 XtSetArg (al
[ac
], XtNallowResize
, 1); ac
++;
2657 XtSetArg (al
[ac
], XtNresizeToPreferred
, 1); ac
++;
2658 XtSetArg (al
[ac
], XtNemacsFrame
, f
); ac
++;
2659 XtSetArg (al
[ac
], XtNvisual
, FRAME_X_VISUAL (f
)); ac
++;
2660 XtSetArg (al
[ac
], XtNdepth
, FRAME_X_DISPLAY_INFO (f
)->n_planes
); ac
++;
2661 XtSetArg (al
[ac
], XtNcolormap
, FRAME_X_COLORMAP (f
)); ac
++;
2662 frame_widget
= XtCreateWidget (f
->namebuf
, emacsFrameClass
, pane_widget
,
2665 f
->output_data
.x
->edit_widget
= frame_widget
;
2667 XtManageChild (frame_widget
);
2669 /* Do some needed geometry management. */
2672 char *tem
, shell_position
[32];
2675 int extra_borders
= 0;
2677 = (f
->output_data
.x
->menubar_widget
2678 ? (f
->output_data
.x
->menubar_widget
->core
.height
2679 + f
->output_data
.x
->menubar_widget
->core
.border_width
)
2682 #if 0 /* Experimentally, we now get the right results
2683 for -geometry -0-0 without this. 24 Aug 96, rms. */
2684 if (FRAME_EXTERNAL_MENU_BAR (f
))
2687 XtVaGetValues (pane_widget
, XtNinternalBorderWidth
, &ibw
, NULL
);
2688 menubar_size
+= ibw
;
2692 f
->output_data
.x
->menubar_height
= menubar_size
;
2695 /* Motif seems to need this amount added to the sizes
2696 specified for the shell widget. The Athena/Lucid widgets don't.
2697 Both conclusions reached experimentally. -- rms. */
2698 XtVaGetValues (f
->output_data
.x
->edit_widget
, XtNinternalBorderWidth
,
2699 &extra_borders
, NULL
);
2703 /* Convert our geometry parameters into a geometry string
2705 Note that we do not specify here whether the position
2706 is a user-specified or program-specified one.
2707 We pass that information later, in x_wm_set_size_hints. */
2709 int left
= f
->left_pos
;
2710 int xneg
= window_prompting
& XNegative
;
2711 int top
= f
->top_pos
;
2712 int yneg
= window_prompting
& YNegative
;
2718 if (window_prompting
& USPosition
)
2719 sprintf (shell_position
, "=%dx%d%c%d%c%d",
2720 FRAME_PIXEL_WIDTH (f
) + extra_borders
,
2721 FRAME_PIXEL_HEIGHT (f
) + menubar_size
+ extra_borders
,
2722 (xneg
? '-' : '+'), left
,
2723 (yneg
? '-' : '+'), top
);
2726 sprintf (shell_position
, "=%dx%d",
2727 FRAME_PIXEL_WIDTH (f
) + extra_borders
,
2728 FRAME_PIXEL_HEIGHT (f
) + menubar_size
+ extra_borders
);
2730 /* Setting x and y when the position is not specified in
2731 the geometry string will set program position in the WM hints.
2732 If Emacs had just one program position, we could set it in
2733 fallback resources, but since each make-frame call can specify
2734 different program positions, this is easier. */
2735 XtSetArg (al
[ac
], XtNx
, left
); ac
++;
2736 XtSetArg (al
[ac
], XtNy
, top
); ac
++;
2740 len
= strlen (shell_position
) + 1;
2741 /* We don't free this because we don't know whether
2742 it is safe to free it while the frame exists.
2743 It isn't worth the trouble of arranging to free it
2744 when the frame is deleted. */
2745 tem
= (char *) xmalloc (len
);
2746 strncpy (tem
, shell_position
, len
);
2747 XtSetArg (al
[ac
], XtNgeometry
, tem
); ac
++;
2748 XtSetValues (shell_widget
, al
, ac
);
2751 XtManageChild (pane_widget
);
2752 XtRealizeWidget (shell_widget
);
2754 FRAME_X_WINDOW (f
) = XtWindow (frame_widget
);
2756 validate_x_resource_name ();
2758 class_hints
.res_name
= (char *) SDATA (Vx_resource_name
);
2759 class_hints
.res_class
= (char *) SDATA (Vx_resource_class
);
2760 XSetClassHint (FRAME_X_DISPLAY (f
), XtWindow (shell_widget
), &class_hints
);
2763 FRAME_XIC (f
) = NULL
;
2765 create_frame_xic (f
);
2768 f
->output_data
.x
->wm_hints
.input
= True
;
2769 f
->output_data
.x
->wm_hints
.flags
|= InputHint
;
2770 XSetWMHints (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2771 &f
->output_data
.x
->wm_hints
);
2773 hack_wm_protocols (f
, shell_widget
);
2776 XtAddEventHandler (shell_widget
, 0, True
, _XEditResCheckMessages
, 0);
2779 /* Do a stupid property change to force the server to generate a
2780 PropertyNotify event so that the event_stream server timestamp will
2781 be initialized to something relevant to the time we created the window.
2783 XChangeProperty (XtDisplay (frame_widget
), XtWindow (frame_widget
),
2784 FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_protocols
,
2785 XA_ATOM
, 32, PropModeAppend
,
2786 (unsigned char*) NULL
, 0);
2788 /* Make all the standard events reach the Emacs frame. */
2789 attributes
.event_mask
= STANDARD_EVENT_SET
;
2794 /* XIM server might require some X events. */
2795 unsigned long fevent
= NoEventMask
;
2796 XGetICValues (FRAME_XIC (f
), XNFilterEvents
, &fevent
, NULL
);
2797 attributes
.event_mask
|= fevent
;
2799 #endif /* HAVE_X_I18N */
2801 attribute_mask
= CWEventMask
;
2802 XChangeWindowAttributes (XtDisplay (shell_widget
), XtWindow (shell_widget
),
2803 attribute_mask
, &attributes
);
2805 XtMapWidget (frame_widget
);
2807 /* x_set_name normally ignores requests to set the name if the
2808 requested name is the same as the current name. This is the one
2809 place where that assumption isn't correct; f->name is set, but
2810 the X server hasn't been told. */
2813 int explicit = f
->explicit_name
;
2815 f
->explicit_name
= 0;
2818 x_set_name (f
, name
, explicit);
2821 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2822 f
->output_data
.x
->text_cursor
);
2826 /* This is a no-op, except under Motif. Make sure main areas are
2827 set to something reasonable, in case we get an error later. */
2828 lw_set_main_areas (pane_widget
, 0, frame_widget
);
2831 #else /* not USE_X_TOOLKIT */
2837 if (! xg_create_frame_widgets (f
))
2838 error ("Unable to create window");
2841 FRAME_XIC (f
) = NULL
;
2845 create_frame_xic (f
);
2848 /* XIM server might require some X events. */
2849 unsigned long fevent
= NoEventMask
;
2850 XGetICValues (FRAME_XIC (f
), XNFilterEvents
, &fevent
, NULL
);
2852 if (fevent
!= NoEventMask
)
2854 XSetWindowAttributes attributes
;
2855 XWindowAttributes wattr
;
2856 unsigned long attribute_mask
;
2858 XGetWindowAttributes (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2860 attributes
.event_mask
= wattr
.your_event_mask
| fevent
;
2861 attribute_mask
= CWEventMask
;
2862 XChangeWindowAttributes (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2863 attribute_mask
, &attributes
);
2871 #else /*! USE_GTK */
2872 /* Create and set up the X window for frame F. */
2879 XClassHint class_hints
;
2880 XSetWindowAttributes attributes
;
2881 unsigned long attribute_mask
;
2883 attributes
.background_pixel
= f
->output_data
.x
->background_pixel
;
2884 attributes
.border_pixel
= f
->output_data
.x
->border_pixel
;
2885 attributes
.bit_gravity
= StaticGravity
;
2886 attributes
.backing_store
= NotUseful
;
2887 attributes
.save_under
= True
;
2888 attributes
.event_mask
= STANDARD_EVENT_SET
;
2889 attributes
.colormap
= FRAME_X_COLORMAP (f
);
2890 attribute_mask
= (CWBackPixel
| CWBorderPixel
| CWBitGravity
| CWEventMask
2895 = XCreateWindow (FRAME_X_DISPLAY (f
),
2896 f
->output_data
.x
->parent_desc
,
2899 FRAME_PIXEL_WIDTH (f
), FRAME_PIXEL_HEIGHT (f
),
2901 CopyFromParent
, /* depth */
2902 InputOutput
, /* class */
2904 attribute_mask
, &attributes
);
2909 create_frame_xic (f
);
2912 /* XIM server might require some X events. */
2913 unsigned long fevent
= NoEventMask
;
2914 XGetICValues (FRAME_XIC (f
), XNFilterEvents
, &fevent
, NULL
);
2915 attributes
.event_mask
|= fevent
;
2916 attribute_mask
= CWEventMask
;
2917 XChangeWindowAttributes (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2918 attribute_mask
, &attributes
);
2921 #endif /* HAVE_X_I18N */
2923 validate_x_resource_name ();
2925 class_hints
.res_name
= (char *) SDATA (Vx_resource_name
);
2926 class_hints
.res_class
= (char *) SDATA (Vx_resource_class
);
2927 XSetClassHint (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), &class_hints
);
2929 /* The menubar is part of the ordinary display;
2930 it does not count in addition to the height of the window. */
2931 f
->output_data
.x
->menubar_height
= 0;
2933 /* This indicates that we use the "Passive Input" input model.
2934 Unless we do this, we don't get the Focus{In,Out} events that we
2935 need to draw the cursor correctly. Accursed bureaucrats.
2936 XWhipsAndChains (FRAME_X_DISPLAY (f), IronMaiden, &TheRack); */
2938 f
->output_data
.x
->wm_hints
.input
= True
;
2939 f
->output_data
.x
->wm_hints
.flags
|= InputHint
;
2940 XSetWMHints (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2941 &f
->output_data
.x
->wm_hints
);
2942 f
->output_data
.x
->wm_hints
.icon_pixmap
= None
;
2944 /* Request "save yourself" and "delete window" commands from wm. */
2947 protocols
[0] = FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_delete_window
;
2948 protocols
[1] = FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_save_yourself
;
2949 XSetWMProtocols (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), protocols
, 2);
2952 /* x_set_name normally ignores requests to set the name if the
2953 requested name is the same as the current name. This is the one
2954 place where that assumption isn't correct; f->name is set, but
2955 the X server hasn't been told. */
2958 int explicit = f
->explicit_name
;
2960 f
->explicit_name
= 0;
2963 x_set_name (f
, name
, explicit);
2966 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2967 f
->output_data
.x
->text_cursor
);
2971 if (FRAME_X_WINDOW (f
) == 0)
2972 error ("Unable to create window");
2975 #endif /* not USE_GTK */
2976 #endif /* not USE_X_TOOLKIT */
2978 /* Handle the icon stuff for this window. Perhaps later we might
2979 want an x_set_icon_position which can be called interactively as
2987 Lisp_Object icon_x
, icon_y
;
2988 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
2990 /* Set the position of the icon. Note that twm groups all
2991 icons in an icon window. */
2992 icon_x
= x_frame_get_and_record_arg (f
, parms
, Qicon_left
, 0, 0, RES_TYPE_NUMBER
);
2993 icon_y
= x_frame_get_and_record_arg (f
, parms
, Qicon_top
, 0, 0, RES_TYPE_NUMBER
);
2994 if (!EQ (icon_x
, Qunbound
) && !EQ (icon_y
, Qunbound
))
2996 CHECK_NUMBER (icon_x
);
2997 CHECK_NUMBER (icon_y
);
2999 else if (!EQ (icon_x
, Qunbound
) || !EQ (icon_y
, Qunbound
))
3000 error ("Both left and top icon corners of icon must be specified");
3004 if (! EQ (icon_x
, Qunbound
))
3005 x_wm_set_icon_position (f
, XINT (icon_x
), XINT (icon_y
));
3007 /* Start up iconic or window? */
3008 x_wm_set_window_state
3009 (f
, (EQ (x_get_arg (dpyinfo
, parms
, Qvisibility
, 0, 0, RES_TYPE_SYMBOL
),
3014 x_text_icon (f
, (char *) SDATA ((!NILP (f
->icon_name
)
3021 /* Make the GCs needed for this window, setting the
3022 background, border and mouse colors; also create the
3023 mouse cursor and the gray border tile. */
3025 static char cursor_bits
[] =
3027 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
3028 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
3029 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
3030 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
3037 XGCValues gc_values
;
3041 /* Create the GCs of this frame.
3042 Note that many default values are used. */
3045 gc_values
.font
= FRAME_FONT (f
)->fid
;
3046 gc_values
.foreground
= f
->output_data
.x
->foreground_pixel
;
3047 gc_values
.background
= f
->output_data
.x
->background_pixel
;
3048 gc_values
.line_width
= 0; /* Means 1 using fast algorithm. */
3049 f
->output_data
.x
->normal_gc
3050 = XCreateGC (FRAME_X_DISPLAY (f
),
3052 GCLineWidth
| GCFont
| GCForeground
| GCBackground
,
3055 /* Reverse video style. */
3056 gc_values
.foreground
= f
->output_data
.x
->background_pixel
;
3057 gc_values
.background
= f
->output_data
.x
->foreground_pixel
;
3058 f
->output_data
.x
->reverse_gc
3059 = XCreateGC (FRAME_X_DISPLAY (f
),
3061 GCFont
| GCForeground
| GCBackground
| GCLineWidth
,
3064 /* Cursor has cursor-color background, background-color foreground. */
3065 gc_values
.foreground
= f
->output_data
.x
->background_pixel
;
3066 gc_values
.background
= f
->output_data
.x
->cursor_pixel
;
3067 gc_values
.fill_style
= FillOpaqueStippled
;
3069 = XCreateBitmapFromData (FRAME_X_DISPLAY (f
),
3070 FRAME_X_DISPLAY_INFO (f
)->root_window
,
3071 cursor_bits
, 16, 16);
3072 f
->output_data
.x
->cursor_gc
3073 = XCreateGC (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
3074 (GCFont
| GCForeground
| GCBackground
3075 | GCFillStyle
/* | GCStipple */ | GCLineWidth
),
3079 f
->output_data
.x
->white_relief
.gc
= 0;
3080 f
->output_data
.x
->black_relief
.gc
= 0;
3082 /* Create the gray border tile used when the pointer is not in
3083 the frame. Since this depends on the frame's pixel values,
3084 this must be done on a per-frame basis. */
3085 f
->output_data
.x
->border_tile
3086 = (XCreatePixmapFromBitmapData
3087 (FRAME_X_DISPLAY (f
), FRAME_X_DISPLAY_INFO (f
)->root_window
,
3088 gray_bits
, gray_width
, gray_height
,
3089 f
->output_data
.x
->foreground_pixel
,
3090 f
->output_data
.x
->background_pixel
,
3091 DefaultDepth (FRAME_X_DISPLAY (f
), FRAME_X_SCREEN_NUMBER (f
))));
3097 /* Free what was was allocated in x_make_gc. */
3103 Display
*dpy
= FRAME_X_DISPLAY (f
);
3107 if (f
->output_data
.x
->normal_gc
)
3109 XFreeGC (dpy
, f
->output_data
.x
->normal_gc
);
3110 f
->output_data
.x
->normal_gc
= 0;
3113 if (f
->output_data
.x
->reverse_gc
)
3115 XFreeGC (dpy
, f
->output_data
.x
->reverse_gc
);
3116 f
->output_data
.x
->reverse_gc
= 0;
3119 if (f
->output_data
.x
->cursor_gc
)
3121 XFreeGC (dpy
, f
->output_data
.x
->cursor_gc
);
3122 f
->output_data
.x
->cursor_gc
= 0;
3125 if (f
->output_data
.x
->border_tile
)
3127 XFreePixmap (dpy
, f
->output_data
.x
->border_tile
);
3128 f
->output_data
.x
->border_tile
= 0;
3135 /* Handler for signals raised during x_create_frame and
3136 x_create_top_frame. FRAME is the frame which is partially
3140 unwind_create_frame (frame
)
3143 struct frame
*f
= XFRAME (frame
);
3145 /* If frame is ``official'', nothing to do. */
3146 if (!CONSP (Vframe_list
) || !EQ (XCAR (Vframe_list
), frame
))
3149 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
3152 x_free_frame_resources (f
);
3154 /* Check that reference counts are indeed correct. */
3155 xassert (dpyinfo
->reference_count
== dpyinfo_refcount
);
3156 xassert (dpyinfo
->image_cache
->refcount
== image_cache_refcount
);
3164 DEFUN ("x-create-frame", Fx_create_frame
, Sx_create_frame
,
3166 doc
: /* Make a new X window, which is called a "frame" in Emacs terms.
3167 Returns an Emacs frame object.
3168 ALIST is an alist of frame parameters.
3169 If the parameters specify that the frame should not have a minibuffer,
3170 and do not specify a specific minibuffer window to use,
3171 then `default-minibuffer-frame' must be a frame whose minibuffer can
3172 be shared by the new frame.
3174 This function is an internal primitive--use `make-frame' instead. */)
3179 Lisp_Object frame
, tem
;
3181 int minibuffer_only
= 0;
3182 long window_prompting
= 0;
3184 int count
= SPECPDL_INDEX ();
3185 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
3186 Lisp_Object display
;
3187 struct x_display_info
*dpyinfo
= NULL
;
3193 /* Use this general default value to start with
3194 until we know if this frame has a specified name. */
3195 Vx_resource_name
= Vinvocation_name
;
3197 display
= x_get_arg (dpyinfo
, parms
, Qdisplay
, 0, 0, RES_TYPE_STRING
);
3198 if (EQ (display
, Qunbound
))
3200 dpyinfo
= check_x_display_info (display
);
3202 kb
= dpyinfo
->kboard
;
3204 kb
= &the_only_kboard
;
3207 name
= x_get_arg (dpyinfo
, parms
, Qname
, "name", "Name", RES_TYPE_STRING
);
3209 && ! EQ (name
, Qunbound
)
3211 error ("Invalid frame name--not a string or nil");
3214 Vx_resource_name
= name
;
3216 /* See if parent window is specified. */
3217 parent
= x_get_arg (dpyinfo
, parms
, Qparent_id
, NULL
, NULL
, RES_TYPE_NUMBER
);
3218 if (EQ (parent
, Qunbound
))
3220 if (! NILP (parent
))
3221 CHECK_NUMBER (parent
);
3223 /* make_frame_without_minibuffer can run Lisp code and garbage collect. */
3224 /* No need to protect DISPLAY because that's not used after passing
3225 it to make_frame_without_minibuffer. */
3227 GCPRO4 (parms
, parent
, name
, frame
);
3228 tem
= x_get_arg (dpyinfo
, parms
, Qminibuffer
, "minibuffer", "Minibuffer",
3230 if (EQ (tem
, Qnone
) || NILP (tem
))
3231 f
= make_frame_without_minibuffer (Qnil
, kb
, display
);
3232 else if (EQ (tem
, Qonly
))
3234 f
= make_minibuffer_frame ();
3235 minibuffer_only
= 1;
3237 else if (WINDOWP (tem
))
3238 f
= make_frame_without_minibuffer (tem
, kb
, display
);
3242 XSETFRAME (frame
, f
);
3244 /* Note that X Windows does support scroll bars. */
3245 FRAME_CAN_HAVE_SCROLL_BARS (f
) = 1;
3247 f
->display
= dpyinfo
->frame_display
;
3248 f
->display
->reference_count
++;
3250 f
->output_method
= output_x_window
;
3251 f
->output_data
.x
= (struct x_output
*) xmalloc (sizeof (struct x_output
));
3252 bzero (f
->output_data
.x
, sizeof (struct x_output
));
3253 f
->output_data
.x
->icon_bitmap
= -1;
3254 FRAME_FONTSET (f
) = -1;
3255 f
->output_data
.x
->scroll_bar_foreground_pixel
= -1;
3256 f
->output_data
.x
->scroll_bar_background_pixel
= -1;
3257 #ifdef USE_TOOLKIT_SCROLL_BARS
3258 f
->output_data
.x
->scroll_bar_top_shadow_pixel
= -1;
3259 f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
= -1;
3260 #endif /* USE_TOOLKIT_SCROLL_BARS */
3261 record_unwind_protect (unwind_create_frame
, frame
);
3264 = x_get_arg (dpyinfo
, parms
, Qicon_name
, "iconName", "Title",
3266 if (! STRINGP (f
->icon_name
))
3267 f
->icon_name
= Qnil
;
3269 FRAME_X_DISPLAY_INFO (f
) = dpyinfo
;
3271 image_cache_refcount
= FRAME_X_IMAGE_CACHE (f
)->refcount
;
3272 dpyinfo_refcount
= dpyinfo
->reference_count
;
3273 #endif /* GLYPH_DEBUG */
3275 FRAME_KBOARD (f
) = kb
;
3278 /* These colors will be set anyway later, but it's important
3279 to get the color reference counts right, so initialize them! */
3282 struct gcpro gcpro1
;
3284 /* Function x_decode_color can signal an error. Make
3285 sure to initialize color slots so that we won't try
3286 to free colors we haven't allocated. */
3287 f
->output_data
.x
->foreground_pixel
= -1;
3288 f
->output_data
.x
->background_pixel
= -1;
3289 f
->output_data
.x
->cursor_pixel
= -1;
3290 f
->output_data
.x
->cursor_foreground_pixel
= -1;
3291 f
->output_data
.x
->border_pixel
= -1;
3292 f
->output_data
.x
->mouse_pixel
= -1;
3294 black
= build_string ("black");
3296 f
->output_data
.x
->foreground_pixel
3297 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
3298 f
->output_data
.x
->background_pixel
3299 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
3300 f
->output_data
.x
->cursor_pixel
3301 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
3302 f
->output_data
.x
->cursor_foreground_pixel
3303 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
3304 f
->output_data
.x
->border_pixel
3305 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
3306 f
->output_data
.x
->mouse_pixel
3307 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
3311 /* Specify the parent under which to make this X window. */
3315 f
->output_data
.x
->parent_desc
= (Window
) XFASTINT (parent
);
3316 f
->output_data
.x
->explicit_parent
= 1;
3320 f
->output_data
.x
->parent_desc
= FRAME_X_DISPLAY_INFO (f
)->root_window
;
3321 f
->output_data
.x
->explicit_parent
= 0;
3324 /* Set the name; the functions to which we pass f expect the name to
3326 if (EQ (name
, Qunbound
) || NILP (name
))
3328 f
->name
= build_string (dpyinfo
->x_id_name
);
3329 f
->explicit_name
= 0;
3334 f
->explicit_name
= 1;
3335 /* use the frame's title when getting resources for this frame. */
3336 specbind (Qx_resource_name
, name
);
3339 /* Extract the window parameters from the supplied values
3340 that are needed to determine window geometry. */
3344 font
= x_get_arg (dpyinfo
, parms
, Qfont
, "font", "Font", RES_TYPE_STRING
);
3347 /* First, try whatever font the caller has specified. */
3350 tem
= Fquery_fontset (font
, Qnil
);
3352 font
= x_new_fontset (f
, SDATA (tem
));
3354 font
= x_new_font (f
, SDATA (font
));
3357 /* Try out a font which we hope has bold and italic variations. */
3358 if (!STRINGP (font
))
3359 font
= x_new_font (f
, "-adobe-courier-medium-r-*-*-*-120-*-*-*-*-iso8859-1");
3360 if (!STRINGP (font
))
3361 font
= x_new_font (f
, "-misc-fixed-medium-r-normal-*-*-140-*-*-c-*-iso8859-1");
3362 if (! STRINGP (font
))
3363 font
= x_new_font (f
, "-*-*-medium-r-normal-*-*-140-*-*-c-*-iso8859-1");
3364 if (! STRINGP (font
))
3365 /* This was formerly the first thing tried, but it finds too many fonts
3366 and takes too long. */
3367 font
= x_new_font (f
, "-*-*-medium-r-*-*-*-*-*-*-c-*-iso8859-1");
3368 /* If those didn't work, look for something which will at least work. */
3369 if (! STRINGP (font
))
3370 font
= x_new_font (f
, "-*-fixed-*-*-*-*-*-140-*-*-c-*-iso8859-1");
3372 if (! STRINGP (font
))
3373 font
= build_string ("fixed");
3375 x_default_parameter (f
, parms
, Qfont
, font
,
3376 "font", "Font", RES_TYPE_STRING
);
3380 /* Prevent lwlib/xlwmenu.c from crashing because of a bug
3381 whereby it fails to get any font. */
3382 xlwmenu_default_font
= FRAME_FONT (f
);
3385 x_default_parameter (f
, parms
, Qborder_width
, make_number (2),
3386 "borderWidth", "BorderWidth", RES_TYPE_NUMBER
);
3388 /* This defaults to 1 in order to match xterm. We recognize either
3389 internalBorderWidth or internalBorder (which is what xterm calls
3391 if (NILP (Fassq (Qinternal_border_width
, parms
)))
3395 value
= x_get_arg (dpyinfo
, parms
, Qinternal_border_width
,
3396 "internalBorder", "internalBorder", RES_TYPE_NUMBER
);
3397 if (! EQ (value
, Qunbound
))
3398 parms
= Fcons (Fcons (Qinternal_border_width
, value
),
3401 x_default_parameter (f
, parms
, Qinternal_border_width
, make_number (1),
3402 "internalBorderWidth", "internalBorderWidth",
3404 x_default_parameter (f
, parms
, Qvertical_scroll_bars
, Qleft
,
3405 "verticalScrollBars", "ScrollBars",
3408 /* Also do the stuff which must be set before the window exists. */
3409 x_default_parameter (f
, parms
, Qforeground_color
, build_string ("black"),
3410 "foreground", "Foreground", RES_TYPE_STRING
);
3411 x_default_parameter (f
, parms
, Qbackground_color
, build_string ("white"),
3412 "background", "Background", RES_TYPE_STRING
);
3413 x_default_parameter (f
, parms
, Qmouse_color
, build_string ("black"),
3414 "pointerColor", "Foreground", RES_TYPE_STRING
);
3415 x_default_parameter (f
, parms
, Qcursor_color
, build_string ("black"),
3416 "cursorColor", "Foreground", RES_TYPE_STRING
);
3417 x_default_parameter (f
, parms
, Qborder_color
, build_string ("black"),
3418 "borderColor", "BorderColor", RES_TYPE_STRING
);
3419 x_default_parameter (f
, parms
, Qscreen_gamma
, Qnil
,
3420 "screenGamma", "ScreenGamma", RES_TYPE_FLOAT
);
3421 x_default_parameter (f
, parms
, Qline_spacing
, Qnil
,
3422 "lineSpacing", "LineSpacing", RES_TYPE_NUMBER
);
3423 x_default_parameter (f
, parms
, Qleft_fringe
, Qnil
,
3424 "leftFringe", "LeftFringe", RES_TYPE_NUMBER
);
3425 x_default_parameter (f
, parms
, Qright_fringe
, Qnil
,
3426 "rightFringe", "RightFringe", RES_TYPE_NUMBER
);
3428 x_default_scroll_bar_color_parameter (f
, parms
, Qscroll_bar_foreground
,
3429 "scrollBarForeground",
3430 "ScrollBarForeground", 1);
3431 x_default_scroll_bar_color_parameter (f
, parms
, Qscroll_bar_background
,
3432 "scrollBarBackground",
3433 "ScrollBarBackground", 0);
3435 /* Init faces before x_default_parameter is called for scroll-bar
3436 parameters because that function calls x_set_scroll_bar_width,
3437 which calls change_frame_size, which calls Fset_window_buffer,
3438 which runs hooks, which call Fvertical_motion. At the end, we
3439 end up in init_iterator with a null face cache, which should not
3441 init_frame_faces (f
);
3443 x_default_parameter (f
, parms
, Qmenu_bar_lines
, make_number (1),
3444 "menuBar", "MenuBar", RES_TYPE_NUMBER
);
3445 x_default_parameter (f
, parms
, Qtool_bar_lines
, make_number (1),
3446 "toolBar", "ToolBar", RES_TYPE_NUMBER
);
3447 x_default_parameter (f
, parms
, Qbuffer_predicate
, Qnil
,
3448 "bufferPredicate", "BufferPredicate",
3450 x_default_parameter (f
, parms
, Qtitle
, Qnil
,
3451 "title", "Title", RES_TYPE_STRING
);
3452 x_default_parameter (f
, parms
, Qwait_for_wm
, Qt
,
3453 "waitForWM", "WaitForWM", RES_TYPE_BOOLEAN
);
3454 x_default_parameter (f
, parms
, Qfullscreen
, Qnil
,
3455 "fullscreen", "Fullscreen", RES_TYPE_SYMBOL
);
3457 f
->output_data
.x
->parent_desc
= FRAME_X_DISPLAY_INFO (f
)->root_window
;
3459 /* Compute the size of the X window. */
3460 window_prompting
= x_figure_window_size (f
, parms
, 1);
3462 tem
= x_get_arg (dpyinfo
, parms
, Qunsplittable
, 0, 0, RES_TYPE_BOOLEAN
);
3463 f
->no_split
= minibuffer_only
|| EQ (tem
, Qt
);
3465 /* Create the X widget or window. */
3466 #ifdef USE_X_TOOLKIT
3467 x_window (f
, window_prompting
, minibuffer_only
);
3475 /* Now consider the frame official. */
3476 FRAME_X_DISPLAY_INFO (f
)->reference_count
++;
3477 Vframe_list
= Fcons (frame
, Vframe_list
);
3479 /* We need to do this after creating the X window, so that the
3480 icon-creation functions can say whose icon they're describing. */
3481 x_default_parameter (f
, parms
, Qicon_type
, Qnil
,
3482 "bitmapIcon", "BitmapIcon", RES_TYPE_SYMBOL
);
3484 x_default_parameter (f
, parms
, Qauto_raise
, Qnil
,
3485 "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
3486 x_default_parameter (f
, parms
, Qauto_lower
, Qnil
,
3487 "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
3488 x_default_parameter (f
, parms
, Qcursor_type
, Qbox
,
3489 "cursorType", "CursorType", RES_TYPE_SYMBOL
);
3490 x_default_parameter (f
, parms
, Qscroll_bar_width
, Qnil
,
3491 "scrollBarWidth", "ScrollBarWidth",
3494 /* Dimensions, especially FRAME_LINES (f), must be done via change_frame_size.
3495 Change will not be effected unless different from the current
3497 width
= FRAME_COLS (f
);
3498 height
= FRAME_LINES (f
);
3500 SET_FRAME_COLS (f
, 0);
3501 FRAME_LINES (f
) = 0;
3502 change_frame_size (f
, height
, width
, 1, 0, 0);
3504 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
3505 /* Create the menu bar. */
3506 if (!minibuffer_only
&& FRAME_EXTERNAL_MENU_BAR (f
))
3508 /* If this signals an error, we haven't set size hints for the
3509 frame and we didn't make it visible. */
3510 initialize_frame_menubar (f
);
3513 /* This is a no-op, except under Motif where it arranges the
3514 main window for the widgets on it. */
3515 lw_set_main_areas (f
->output_data
.x
->column_widget
,
3516 f
->output_data
.x
->menubar_widget
,
3517 f
->output_data
.x
->edit_widget
);
3518 #endif /* not USE_GTK */
3520 #endif /* USE_X_TOOLKIT || USE_GTK */
3522 /* Tell the server what size and position, etc, we want, and how
3523 badly we want them. This should be done after we have the menu
3524 bar so that its size can be taken into account. */
3526 x_wm_set_size_hint (f
, window_prompting
, 0);
3529 /* Make the window appear on the frame and enable display, unless
3530 the caller says not to. However, with explicit parent, Emacs
3531 cannot control visibility, so don't try. */
3532 if (! f
->output_data
.x
->explicit_parent
)
3534 Lisp_Object visibility
;
3536 visibility
= x_get_arg (dpyinfo
, parms
, Qvisibility
, 0, 0,
3538 if (EQ (visibility
, Qunbound
))
3541 if (EQ (visibility
, Qicon
))
3542 x_iconify_frame (f
);
3543 else if (! NILP (visibility
))
3544 x_make_frame_visible (f
);
3546 /* Must have been Qnil. */
3550 /* Set the WM leader property. GTK does this itself, so this is not
3551 needed when using GTK. */
3552 if (dpyinfo
->client_leader_window
!= 0)
3555 XChangeProperty (FRAME_X_DISPLAY (f
),
3556 FRAME_OUTER_WINDOW (f
),
3557 dpyinfo
->Xatom_wm_client_leader
,
3558 XA_WINDOW
, 32, PropModeReplace
,
3559 (char *) &dpyinfo
->client_leader_window
, 1);
3565 /* Make sure windows on this frame appear in calls to next-window
3566 and similar functions. */
3567 Vwindow_list
= Qnil
;
3569 return unbind_to (count
, frame
);
3573 /* FRAME is used only to get a handle on the X display. We don't pass the
3574 display info directly because we're called from frame.c, which doesn't
3575 know about that structure. */
3578 x_get_focus_frame (frame
)
3579 struct frame
*frame
;
3581 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (frame
);
3583 if (! dpyinfo
->x_focus_frame
)
3586 XSETFRAME (xfocus
, dpyinfo
->x_focus_frame
);
3591 /* In certain situations, when the window manager follows a
3592 click-to-focus policy, there seems to be no way around calling
3593 XSetInputFocus to give another frame the input focus .
3595 In an ideal world, XSetInputFocus should generally be avoided so
3596 that applications don't interfere with the window manager's focus
3597 policy. But I think it's okay to use when it's clearly done
3598 following a user-command. */
3600 DEFUN ("x-focus-frame", Fx_focus_frame
, Sx_focus_frame
, 1, 1, 0,
3601 doc
: /* Set the input focus to FRAME.
3602 FRAME nil means use the selected frame. */)
3606 struct frame
*f
= check_x_frame (frame
);
3607 Display
*dpy
= FRAME_X_DISPLAY (f
);
3611 count
= x_catch_errors (dpy
);
3612 XSetInputFocus (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
3613 RevertToParent
, CurrentTime
);
3614 x_uncatch_errors (dpy
, count
);
3621 DEFUN ("xw-color-defined-p", Fxw_color_defined_p
, Sxw_color_defined_p
, 1, 2, 0,
3622 doc
: /* Internal function called by `color-defined-p', which see. */)
3624 Lisp_Object color
, frame
;
3627 FRAME_PTR f
= check_x_frame (frame
);
3629 CHECK_STRING (color
);
3631 if (x_defined_color (f
, SDATA (color
), &foo
, 0))
3637 DEFUN ("xw-color-values", Fxw_color_values
, Sxw_color_values
, 1, 2, 0,
3638 doc
: /* Internal function called by `color-values', which see. */)
3640 Lisp_Object color
, frame
;
3643 FRAME_PTR f
= check_x_frame (frame
);
3645 CHECK_STRING (color
);
3647 if (x_defined_color (f
, SDATA (color
), &foo
, 0))
3651 rgb
[0] = make_number (foo
.red
);
3652 rgb
[1] = make_number (foo
.green
);
3653 rgb
[2] = make_number (foo
.blue
);
3654 return Flist (3, rgb
);
3660 DEFUN ("xw-display-color-p", Fxw_display_color_p
, Sxw_display_color_p
, 0, 1, 0,
3661 doc
: /* Internal function called by `display-color-p', which see. */)
3663 Lisp_Object display
;
3665 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
3667 if (dpyinfo
->n_planes
<= 2)
3670 switch (dpyinfo
->visual
->class)
3683 DEFUN ("x-display-grayscale-p", Fx_display_grayscale_p
, Sx_display_grayscale_p
,
3685 doc
: /* Return t if the X display supports shades of gray.
3686 Note that color displays do support shades of gray.
3687 The optional argument DISPLAY specifies which display to ask about.
3688 DISPLAY should be either a frame or a display name (a string).
3689 If omitted or nil, that stands for the selected frame's display. */)
3691 Lisp_Object display
;
3693 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
3695 if (dpyinfo
->n_planes
<= 1)
3698 switch (dpyinfo
->visual
->class)
3713 DEFUN ("x-display-pixel-width", Fx_display_pixel_width
, Sx_display_pixel_width
,
3715 doc
: /* Returns the width in pixels of the X display DISPLAY.
3716 The optional argument DISPLAY specifies which display to ask about.
3717 DISPLAY should be either a frame or a display name (a string).
3718 If omitted or nil, that stands for the selected frame's display. */)
3720 Lisp_Object display
;
3722 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
3724 return make_number (dpyinfo
->width
);
3727 DEFUN ("x-display-pixel-height", Fx_display_pixel_height
,
3728 Sx_display_pixel_height
, 0, 1, 0,
3729 doc
: /* Returns the height in pixels of the X display DISPLAY.
3730 The optional argument DISPLAY specifies which display to ask about.
3731 DISPLAY should be either a frame or a display name (a string).
3732 If omitted or nil, that stands for the selected frame's display. */)
3734 Lisp_Object display
;
3736 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
3738 return make_number (dpyinfo
->height
);
3741 DEFUN ("x-display-planes", Fx_display_planes
, Sx_display_planes
,
3743 doc
: /* Returns the number of bitplanes of the X display DISPLAY.
3744 The optional argument DISPLAY specifies which display to ask about.
3745 DISPLAY should be either a frame or a display name (a string).
3746 If omitted or nil, that stands for the selected frame's display. */)
3748 Lisp_Object display
;
3750 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
3752 return make_number (dpyinfo
->n_planes
);
3755 DEFUN ("x-display-color-cells", Fx_display_color_cells
, Sx_display_color_cells
,
3757 doc
: /* Returns the number of color cells of the X display DISPLAY.
3758 The optional argument DISPLAY specifies which display to ask about.
3759 DISPLAY should be either a frame or a display name (a string).
3760 If omitted or nil, that stands for the selected frame's display. */)
3762 Lisp_Object display
;
3764 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
3766 return make_number (DisplayCells (dpyinfo
->display
,
3767 XScreenNumberOfScreen (dpyinfo
->screen
)));
3770 DEFUN ("x-server-max-request-size", Fx_server_max_request_size
,
3771 Sx_server_max_request_size
,
3773 doc
: /* Returns the maximum request size of the X server of display DISPLAY.
3774 The optional argument DISPLAY specifies which display to ask about.
3775 DISPLAY should be either a frame or a display name (a string).
3776 If omitted or nil, that stands for the selected frame's display. */)
3778 Lisp_Object display
;
3780 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
3782 return make_number (MAXREQUEST (dpyinfo
->display
));
3785 DEFUN ("x-server-vendor", Fx_server_vendor
, Sx_server_vendor
, 0, 1, 0,
3786 doc
: /* Returns the vendor ID string of the X server of display DISPLAY.
3787 The optional argument DISPLAY specifies which display to ask about.
3788 DISPLAY should be either a frame or a display name (a string).
3789 If omitted or nil, that stands for the selected frame's display. */)
3791 Lisp_Object display
;
3793 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
3794 char *vendor
= ServerVendor (dpyinfo
->display
);
3796 if (! vendor
) vendor
= "";
3797 return build_string (vendor
);
3800 DEFUN ("x-server-version", Fx_server_version
, Sx_server_version
, 0, 1, 0,
3801 doc
: /* Returns the version numbers of the X server of display DISPLAY.
3802 The value is a list of three integers: the major and minor
3803 version numbers of the X Protocol in use, and the vendor-specific release
3804 number. See also the function `x-server-vendor'.
3806 The optional argument DISPLAY specifies which display to ask about.
3807 DISPLAY should be either a frame or a display name (a string).
3808 If omitted or nil, that stands for the selected frame's display. */)
3810 Lisp_Object display
;
3812 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
3813 Display
*dpy
= dpyinfo
->display
;
3815 return Fcons (make_number (ProtocolVersion (dpy
)),
3816 Fcons (make_number (ProtocolRevision (dpy
)),
3817 Fcons (make_number (VendorRelease (dpy
)), Qnil
)));
3820 DEFUN ("x-display-screens", Fx_display_screens
, Sx_display_screens
, 0, 1, 0,
3821 doc
: /* Return the number of screens on the X server of display DISPLAY.
3822 The optional argument DISPLAY specifies which display to ask about.
3823 DISPLAY should be either a frame or a display name (a string).
3824 If omitted or nil, that stands for the selected frame's display. */)
3826 Lisp_Object display
;
3828 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
3830 return make_number (ScreenCount (dpyinfo
->display
));
3833 DEFUN ("x-display-mm-height", Fx_display_mm_height
, Sx_display_mm_height
, 0, 1, 0,
3834 doc
: /* Return the height in millimeters of the X display DISPLAY.
3835 The optional argument DISPLAY specifies which display to ask about.
3836 DISPLAY should be either a frame or a display name (a string).
3837 If omitted or nil, that stands for the selected frame's display. */)
3839 Lisp_Object display
;
3841 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
3843 return make_number (HeightMMOfScreen (dpyinfo
->screen
));
3846 DEFUN ("x-display-mm-width", Fx_display_mm_width
, Sx_display_mm_width
, 0, 1, 0,
3847 doc
: /* Return the width in millimeters of the X display DISPLAY.
3848 The optional argument DISPLAY specifies which display to ask about.
3849 DISPLAY should be either a frame or a display name (a string).
3850 If omitted or nil, that stands for the selected frame's display. */)
3852 Lisp_Object display
;
3854 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
3856 return make_number (WidthMMOfScreen (dpyinfo
->screen
));
3859 DEFUN ("x-display-backing-store", Fx_display_backing_store
,
3860 Sx_display_backing_store
, 0, 1, 0,
3861 doc
: /* Returns an indication of whether X display DISPLAY does backing store.
3862 The value may be `always', `when-mapped', or `not-useful'.
3863 The optional argument DISPLAY specifies which display to ask about.
3864 DISPLAY should be either a frame or a display name (a string).
3865 If omitted or nil, that stands for the selected frame's display. */)
3867 Lisp_Object display
;
3869 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
3872 switch (DoesBackingStore (dpyinfo
->screen
))
3875 result
= intern ("always");
3879 result
= intern ("when-mapped");
3883 result
= intern ("not-useful");
3887 error ("Strange value for BackingStore parameter of screen");
3894 DEFUN ("x-display-visual-class", Fx_display_visual_class
,
3895 Sx_display_visual_class
, 0, 1, 0,
3896 doc
: /* Return the visual class of the X display DISPLAY.
3897 The value is one of the symbols `static-gray', `gray-scale',
3898 `static-color', `pseudo-color', `true-color', or `direct-color'.
3900 The optional argument DISPLAY specifies which display to ask about.
3901 DISPLAY should be either a frame or a display name (a string).
3902 If omitted or nil, that stands for the selected frame's display. */)
3904 Lisp_Object display
;
3906 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
3909 switch (dpyinfo
->visual
->class)
3912 result
= intern ("static-gray");
3915 result
= intern ("gray-scale");
3918 result
= intern ("static-color");
3921 result
= intern ("pseudo-color");
3924 result
= intern ("true-color");
3927 result
= intern ("direct-color");
3930 error ("Display has an unknown visual class");
3937 DEFUN ("x-display-save-under", Fx_display_save_under
,
3938 Sx_display_save_under
, 0, 1, 0,
3939 doc
: /* Returns t if the X display DISPLAY supports the save-under feature.
3940 The optional argument DISPLAY specifies which display to ask about.
3941 DISPLAY should be either a frame or a display name (a string).
3942 If omitted or nil, that stands for the selected frame's display. */)
3944 Lisp_Object display
;
3946 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
3948 if (DoesSaveUnders (dpyinfo
->screen
) == True
)
3956 register struct frame
*f
;
3958 return FRAME_PIXEL_WIDTH (f
);
3963 register struct frame
*f
;
3965 return FRAME_PIXEL_HEIGHT (f
);
3970 register struct frame
*f
;
3972 return FRAME_COLUMN_WIDTH (f
);
3977 register struct frame
*f
;
3979 return FRAME_LINE_HEIGHT (f
);
3984 register struct frame
*f
;
3986 return FRAME_X_DISPLAY_INFO (f
)->n_planes
;
3991 /************************************************************************
3993 ************************************************************************/
3996 /* Mapping visual names to visuals. */
3998 static struct visual_class
4005 {"StaticGray", StaticGray
},
4006 {"GrayScale", GrayScale
},
4007 {"StaticColor", StaticColor
},
4008 {"PseudoColor", PseudoColor
},
4009 {"TrueColor", TrueColor
},
4010 {"DirectColor", DirectColor
},
4015 #ifndef HAVE_XSCREENNUMBEROFSCREEN
4017 /* Value is the screen number of screen SCR. This is a substitute for
4018 the X function with the same name when that doesn't exist. */
4021 XScreenNumberOfScreen (scr
)
4022 register Screen
*scr
;
4024 Display
*dpy
= scr
->display
;
4027 for (i
= 0; i
< dpy
->nscreens
; ++i
)
4028 if (scr
== dpy
->screens
+ i
)
4034 #endif /* not HAVE_XSCREENNUMBEROFSCREEN */
4037 /* Select the visual that should be used on display DPYINFO. Set
4038 members of DPYINFO appropriately. Called from x_term_init. */
4041 select_visual (dpyinfo
)
4042 struct x_display_info
*dpyinfo
;
4044 Display
*dpy
= dpyinfo
->display
;
4045 Screen
*screen
= dpyinfo
->screen
;
4048 /* See if a visual is specified. */
4049 value
= display_x_get_resource (dpyinfo
,
4050 build_string ("visualClass"),
4051 build_string ("VisualClass"),
4053 if (STRINGP (value
))
4055 /* VALUE should be of the form CLASS-DEPTH, where CLASS is one
4056 of `PseudoColor', `TrueColor' etc. and DEPTH is the color
4057 depth, a decimal number. NAME is compared with case ignored. */
4058 char *s
= (char *) alloca (SBYTES (value
) + 1);
4063 strcpy (s
, SDATA (value
));
4064 dash
= index (s
, '-');
4067 dpyinfo
->n_planes
= atoi (dash
+ 1);
4071 /* We won't find a matching visual with depth 0, so that
4072 an error will be printed below. */
4073 dpyinfo
->n_planes
= 0;
4075 /* Determine the visual class. */
4076 for (i
= 0; visual_classes
[i
].name
; ++i
)
4077 if (xstricmp (s
, visual_classes
[i
].name
) == 0)
4079 class = visual_classes
[i
].class;
4083 /* Look up a matching visual for the specified class. */
4085 || !XMatchVisualInfo (dpy
, XScreenNumberOfScreen (screen
),
4086 dpyinfo
->n_planes
, class, &vinfo
))
4087 fatal ("Invalid visual specification `%s'", SDATA (value
));
4089 dpyinfo
->visual
= vinfo
.visual
;
4094 XVisualInfo
*vinfo
, vinfo_template
;
4096 dpyinfo
->visual
= DefaultVisualOfScreen (screen
);
4099 vinfo_template
.visualid
= XVisualIDFromVisual (dpyinfo
->visual
);
4101 vinfo_template
.visualid
= dpyinfo
->visual
->visualid
;
4103 vinfo_template
.screen
= XScreenNumberOfScreen (screen
);
4104 vinfo
= XGetVisualInfo (dpy
, VisualIDMask
| VisualScreenMask
,
4105 &vinfo_template
, &n_visuals
);
4107 fatal ("Can't get proper X visual info");
4109 dpyinfo
->n_planes
= vinfo
->depth
;
4110 XFree ((char *) vinfo
);
4115 /* Return the X display structure for the display named NAME.
4116 Open a new connection if necessary. */
4118 struct x_display_info
*
4119 x_display_info_for_name (name
)
4123 struct x_display_info
*dpyinfo
;
4125 CHECK_STRING (name
);
4127 if (! EQ (Vwindow_system
, intern ("x")))
4128 error ("Not using X Windows");
4130 for (dpyinfo
= x_display_list
, names
= x_display_name_list
;
4132 dpyinfo
= dpyinfo
->next
, names
= XCDR (names
))
4135 tem
= Fstring_equal (XCAR (XCAR (names
)), name
);
4140 /* Use this general default value to start with. */
4141 Vx_resource_name
= Vinvocation_name
;
4143 validate_x_resource_name ();
4145 dpyinfo
= x_term_init (name
, (char *)0,
4146 (char *) SDATA (Vx_resource_name
));
4149 error ("Cannot connect to X server %s", SDATA (name
));
4152 XSETFASTINT (Vwindow_system_version
, 11);
4158 DEFUN ("x-open-connection", Fx_open_connection
, Sx_open_connection
,
4160 doc
: /* Open a connection to an X server.
4161 DISPLAY is the name of the display to connect to.
4162 Optional second arg XRM-STRING is a string of resources in xrdb format.
4163 If the optional third arg MUST-SUCCEED is non-nil,
4164 terminate Emacs if we can't open the connection. */)
4165 (display
, xrm_string
, must_succeed
)
4166 Lisp_Object display
, xrm_string
, must_succeed
;
4168 unsigned char *xrm_option
;
4169 struct x_display_info
*dpyinfo
;
4171 CHECK_STRING (display
);
4172 if (! NILP (xrm_string
))
4173 CHECK_STRING (xrm_string
);
4175 if (! EQ (Vwindow_system
, intern ("x")))
4176 error ("Not using X Windows");
4178 if (! NILP (xrm_string
))
4179 xrm_option
= (unsigned char *) SDATA (xrm_string
);
4181 xrm_option
= (unsigned char *) 0;
4183 validate_x_resource_name ();
4185 /* This is what opens the connection and sets x_current_display.
4186 This also initializes many symbols, such as those used for input. */
4187 dpyinfo
= x_term_init (display
, xrm_option
,
4188 (char *) SDATA (Vx_resource_name
));
4192 if (!NILP (must_succeed
))
4193 fatal ("Cannot connect to X server %s.\n\
4194 Check the DISPLAY environment variable or use `-d'.\n\
4195 Also use the `xauth' program to verify that you have the proper\n\
4196 authorization information needed to connect the X server.\n\
4197 An insecure way to solve the problem may be to use `xhost'.\n",
4200 error ("Cannot connect to X server %s", SDATA (display
));
4205 XSETFASTINT (Vwindow_system_version
, 11);
4209 DEFUN ("x-close-connection", Fx_close_connection
,
4210 Sx_close_connection
, 1, 1, 0,
4211 doc
: /* Close the connection to DISPLAY's X server.
4212 For DISPLAY, specify either a frame or a display name (a string).
4213 If DISPLAY is nil, that stands for the selected frame's display. */)
4215 Lisp_Object display
;
4217 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
4220 if (dpyinfo
->reference_count
> 0)
4221 error ("Display still has frames on it");
4224 /* Free the fonts in the font table. */
4225 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
4226 if (dpyinfo
->font_table
[i
].name
)
4228 XFreeFont (dpyinfo
->display
, dpyinfo
->font_table
[i
].font
);
4231 x_destroy_all_bitmaps (dpyinfo
);
4232 XSetCloseDownMode (dpyinfo
->display
, DestroyAll
);
4234 #ifdef USE_X_TOOLKIT
4235 XtCloseDisplay (dpyinfo
->display
);
4237 XCloseDisplay (dpyinfo
->display
);
4240 x_delete_display (dpyinfo
);
4246 DEFUN ("x-display-list", Fx_display_list
, Sx_display_list
, 0, 0, 0,
4247 doc
: /* Return the list of display names that Emacs has connections to. */)
4250 Lisp_Object tail
, result
;
4253 for (tail
= x_display_name_list
; ! NILP (tail
); tail
= XCDR (tail
))
4254 result
= Fcons (XCAR (XCAR (tail
)), result
);
4259 DEFUN ("x-synchronize", Fx_synchronize
, Sx_synchronize
, 1, 2, 0,
4260 doc
: /* If ON is non-nil, report X errors as soon as the erring request is made.
4261 If ON is nil, allow buffering of requests.
4262 Turning on synchronization prohibits the Xlib routines from buffering
4263 requests and seriously degrades performance, but makes debugging much
4265 The optional second argument DISPLAY specifies which display to act on.
4266 DISPLAY should be either a frame or a display name (a string).
4267 If DISPLAY is omitted or nil, that stands for the selected frame's display. */)
4269 Lisp_Object display
, on
;
4271 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
4273 XSynchronize (dpyinfo
->display
, !EQ (on
, Qnil
));
4278 /* Wait for responses to all X commands issued so far for frame F. */
4285 XSync (FRAME_X_DISPLAY (f
), False
);
4290 /***********************************************************************
4291 General X functions exposed to Elisp.
4292 ***********************************************************************/
4294 DEFUN ("x-send-client-message", Fx_send_client_event
,
4295 Sx_send_client_message
, 6, 6, 0,
4296 doc
: /* Send a client message of MESSAGE-TYPE to window DEST on DISPLAY.
4298 For DISPLAY, specify either a frame or a display name (a string).
4299 If DISPLAY is nil, that stands for the selected frame's display.
4300 DEST may be an integer, in which case it is a Window id. The value 0 may
4301 be used to send to the root window of the DISPLAY.
4302 If DEST is a frame the event is sent to the outer window of that frame.
4303 Nil means the currently selected frame.
4304 If DEST is the string "PointerWindow" the event is sent to the window that
4305 contains the pointer. If DEST is the string "InputFocus" the event is
4306 sent to the window that has the input focus.
4307 FROM is the frame sending the event. Use nil for currently selected frame.
4308 MESSAGE-TYPE is the name of an Atom as a string.
4309 FORMAT must be one of 8, 16 or 32 and determines the size of the values in
4310 bits. VALUES is a list of integer and/or strings containing the values to
4311 send. If a value is a string, it is converted to an Atom and the value of
4312 the Atom is sent. If more values than fits into the event is given,
4313 the excessive values are ignored. */)
4314 (display
, dest
, from
, message_type
, format
, values
)
4315 Lisp_Object display
, dest
, from
, message_type
, format
, values
;
4317 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
4322 int max_nr_values
= (int) sizeof (event
.xclient
.data
.b
);
4323 struct frame
*f
= check_x_frame (from
);
4325 CHECK_STRING (message_type
);
4326 CHECK_NUMBER (format
);
4327 CHECK_CONS (values
);
4329 for (cons
= values
; CONSP (cons
); cons
= XCDR (cons
))
4331 Lisp_Object o
= XCAR (cons
);
4333 if (! INTEGERP (o
) && ! STRINGP (o
))
4334 error ("Bad data in VALUES, must be integer or string");
4337 event
.xclient
.type
= ClientMessage
;
4338 event
.xclient
.format
= XFASTINT (format
);
4340 if (event
.xclient
.format
!= 8 && event
.xclient
.format
!= 16
4341 && event
.xclient
.format
!= 32)
4342 error ("FORMAT must be one of 8, 16 or 32");
4343 if (event
.xclient
.format
== 16) max_nr_values
/= 2;
4344 if (event
.xclient
.format
== 32) max_nr_values
/= 4;
4346 if (FRAMEP (dest
) || NILP (dest
))
4348 struct frame
*fdest
= check_x_frame (dest
);
4349 wdest
= FRAME_OUTER_WINDOW (fdest
);
4351 else if (STRINGP (dest
))
4353 if (strcmp (SDATA (dest
), "PointerWindow") == 0)
4354 wdest
= PointerWindow
;
4355 else if (strcmp (SDATA (dest
), "InputFocus") == 0)
4358 error ("DEST as a string must be one of PointerWindow or InputFocus");
4362 CHECK_NUMBER (dest
);
4363 wdest
= (Window
) XFASTINT (dest
);
4364 if (wdest
== 0) wdest
= dpyinfo
->root_window
;
4368 for (cons
= values
, i
= 0;
4369 CONSP (cons
) && i
< max_nr_values
;
4370 cons
= XCDR (cons
), ++i
)
4372 Lisp_Object o
= XCAR (cons
);
4377 else if (STRINGP (o
))
4378 val
= XInternAtom (dpyinfo
->display
, SDATA (o
), False
);
4380 if (event
.xclient
.format
== 8)
4381 event
.xclient
.data
.b
[i
] = (char) val
;
4382 else if (event
.xclient
.format
== 16)
4383 event
.xclient
.data
.s
[i
] = (short) val
;
4385 event
.xclient
.data
.l
[i
] = val
;
4388 for ( ; i
< max_nr_values
; ++i
)
4389 if (event
.xclient
.format
== 8)
4390 event
.xclient
.data
.b
[i
] = 0;
4391 else if (event
.xclient
.format
== 16)
4392 event
.xclient
.data
.s
[i
] = 0;
4394 event
.xclient
.data
.l
[i
] = 0;
4396 event
.xclient
.message_type
4397 = XInternAtom (dpyinfo
->display
, SDATA (message_type
), False
);
4398 event
.xclient
.display
= dpyinfo
->display
;
4399 event
.xclient
.window
= FRAME_OUTER_WINDOW (f
);
4401 XSendEvent (dpyinfo
->display
, wdest
, False
, 0xffff, &event
);
4403 XFlush (dpyinfo
->display
);
4409 /***********************************************************************
4411 ***********************************************************************/
4413 /* Value is the number of elements of vector VECTOR. */
4415 #define DIM(VECTOR) (sizeof (VECTOR) / sizeof *(VECTOR))
4417 /* List of supported image types. Use define_image_type to add new
4418 types. Use lookup_image_type to find a type for a given symbol. */
4420 static struct image_type
*image_types
;
4422 /* The symbol `xbm' which is used as the type symbol for XBM images. */
4428 extern Lisp_Object QCwidth
, QCheight
, QCforeground
, QCbackground
, QCfile
;
4429 extern Lisp_Object QCdata
, QCtype
;
4430 Lisp_Object QCascent
, QCmargin
, QCrelief
;
4431 Lisp_Object QCconversion
, QCcolor_symbols
, QCheuristic_mask
;
4432 Lisp_Object QCindex
, QCmatrix
, QCcolor_adjustment
, QCmask
;
4434 /* Other symbols. */
4436 Lisp_Object Qlaplace
, Qemboss
, Qedge_detection
, Qheuristic
;
4438 /* Time in seconds after which images should be removed from the cache
4439 if not displayed. */
4441 Lisp_Object Vimage_cache_eviction_delay
;
4443 /* Function prototypes. */
4445 static void define_image_type
P_ ((struct image_type
*type
));
4446 static struct image_type
*lookup_image_type
P_ ((Lisp_Object symbol
));
4447 static void image_error
P_ ((char *format
, Lisp_Object
, Lisp_Object
));
4448 static void x_laplace
P_ ((struct frame
*, struct image
*));
4449 static void x_emboss
P_ ((struct frame
*, struct image
*));
4450 static int x_build_heuristic_mask
P_ ((struct frame
*, struct image
*,
4454 /* Define a new image type from TYPE. This adds a copy of TYPE to
4455 image_types and adds the symbol *TYPE->type to Vimage_types. */
4458 define_image_type (type
)
4459 struct image_type
*type
;
4461 /* Make a copy of TYPE to avoid a bus error in a dumped Emacs.
4462 The initialized data segment is read-only. */
4463 struct image_type
*p
= (struct image_type
*) xmalloc (sizeof *p
);
4464 bcopy (type
, p
, sizeof *p
);
4465 p
->next
= image_types
;
4467 Vimage_types
= Fcons (*p
->type
, Vimage_types
);
4471 /* Look up image type SYMBOL, and return a pointer to its image_type
4472 structure. Value is null if SYMBOL is not a known image type. */
4474 static INLINE
struct image_type
*
4475 lookup_image_type (symbol
)
4478 struct image_type
*type
;
4480 for (type
= image_types
; type
; type
= type
->next
)
4481 if (EQ (symbol
, *type
->type
))
4488 /* Value is non-zero if OBJECT is a valid Lisp image specification. A
4489 valid image specification is a list whose car is the symbol
4490 `image', and whose rest is a property list. The property list must
4491 contain a value for key `:type'. That value must be the name of a
4492 supported image type. The rest of the property list depends on the
4496 valid_image_p (object
)
4501 if (IMAGEP (object
))
4505 for (tem
= XCDR (object
); CONSP (tem
); tem
= XCDR (tem
))
4506 if (EQ (XCAR (tem
), QCtype
))
4509 if (CONSP (tem
) && SYMBOLP (XCAR (tem
)))
4511 struct image_type
*type
;
4512 type
= lookup_image_type (XCAR (tem
));
4514 valid_p
= type
->valid_p (object
);
4525 /* Log error message with format string FORMAT and argument ARG.
4526 Signaling an error, e.g. when an image cannot be loaded, is not a
4527 good idea because this would interrupt redisplay, and the error
4528 message display would lead to another redisplay. This function
4529 therefore simply displays a message. */
4532 image_error (format
, arg1
, arg2
)
4534 Lisp_Object arg1
, arg2
;
4536 add_to_log (format
, arg1
, arg2
);
4541 /***********************************************************************
4542 Image specifications
4543 ***********************************************************************/
4545 enum image_value_type
4547 IMAGE_DONT_CHECK_VALUE_TYPE
,
4549 IMAGE_STRING_OR_NIL_VALUE
,
4551 IMAGE_POSITIVE_INTEGER_VALUE
,
4552 IMAGE_POSITIVE_INTEGER_VALUE_OR_PAIR
,
4553 IMAGE_NON_NEGATIVE_INTEGER_VALUE
,
4555 IMAGE_INTEGER_VALUE
,
4556 IMAGE_FUNCTION_VALUE
,
4561 /* Structure used when parsing image specifications. */
4563 struct image_keyword
4565 /* Name of keyword. */
4568 /* The type of value allowed. */
4569 enum image_value_type type
;
4571 /* Non-zero means key must be present. */
4574 /* Used to recognize duplicate keywords in a property list. */
4577 /* The value that was found. */
4582 static int parse_image_spec
P_ ((Lisp_Object
, struct image_keyword
*,
4584 static Lisp_Object image_spec_value
P_ ((Lisp_Object
, Lisp_Object
, int *));
4587 /* Parse image spec SPEC according to KEYWORDS. A valid image spec
4588 has the format (image KEYWORD VALUE ...). One of the keyword/
4589 value pairs must be `:type TYPE'. KEYWORDS is a vector of
4590 image_keywords structures of size NKEYWORDS describing other
4591 allowed keyword/value pairs. Value is non-zero if SPEC is valid. */
4594 parse_image_spec (spec
, keywords
, nkeywords
, type
)
4596 struct image_keyword
*keywords
;
4606 plist
= XCDR (spec
);
4607 while (CONSP (plist
))
4609 Lisp_Object key
, value
;
4611 /* First element of a pair must be a symbol. */
4613 plist
= XCDR (plist
);
4617 /* There must follow a value. */
4620 value
= XCAR (plist
);
4621 plist
= XCDR (plist
);
4623 /* Find key in KEYWORDS. Error if not found. */
4624 for (i
= 0; i
< nkeywords
; ++i
)
4625 if (strcmp (keywords
[i
].name
, SDATA (SYMBOL_NAME (key
))) == 0)
4631 /* Record that we recognized the keyword. If a keywords
4632 was found more than once, it's an error. */
4633 keywords
[i
].value
= value
;
4634 ++keywords
[i
].count
;
4636 if (keywords
[i
].count
> 1)
4639 /* Check type of value against allowed type. */
4640 switch (keywords
[i
].type
)
4642 case IMAGE_STRING_VALUE
:
4643 if (!STRINGP (value
))
4647 case IMAGE_STRING_OR_NIL_VALUE
:
4648 if (!STRINGP (value
) && !NILP (value
))
4652 case IMAGE_SYMBOL_VALUE
:
4653 if (!SYMBOLP (value
))
4657 case IMAGE_POSITIVE_INTEGER_VALUE
:
4658 if (!INTEGERP (value
) || XINT (value
) <= 0)
4662 case IMAGE_POSITIVE_INTEGER_VALUE_OR_PAIR
:
4663 if (INTEGERP (value
) && XINT (value
) >= 0)
4666 && INTEGERP (XCAR (value
)) && INTEGERP (XCDR (value
))
4667 && XINT (XCAR (value
)) >= 0 && XINT (XCDR (value
)) >= 0)
4671 case IMAGE_ASCENT_VALUE
:
4672 if (SYMBOLP (value
) && EQ (value
, Qcenter
))
4674 else if (INTEGERP (value
)
4675 && XINT (value
) >= 0
4676 && XINT (value
) <= 100)
4680 case IMAGE_NON_NEGATIVE_INTEGER_VALUE
:
4681 if (!INTEGERP (value
) || XINT (value
) < 0)
4685 case IMAGE_DONT_CHECK_VALUE_TYPE
:
4688 case IMAGE_FUNCTION_VALUE
:
4689 value
= indirect_function (value
);
4691 || COMPILEDP (value
)
4692 || (CONSP (value
) && EQ (XCAR (value
), Qlambda
)))
4696 case IMAGE_NUMBER_VALUE
:
4697 if (!INTEGERP (value
) && !FLOATP (value
))
4701 case IMAGE_INTEGER_VALUE
:
4702 if (!INTEGERP (value
))
4706 case IMAGE_BOOL_VALUE
:
4707 if (!NILP (value
) && !EQ (value
, Qt
))
4716 if (EQ (key
, QCtype
) && !EQ (type
, value
))
4720 /* Check that all mandatory fields are present. */
4721 for (i
= 0; i
< nkeywords
; ++i
)
4722 if (keywords
[i
].mandatory_p
&& keywords
[i
].count
== 0)
4725 return NILP (plist
);
4729 /* Return the value of KEY in image specification SPEC. Value is nil
4730 if KEY is not present in SPEC. if FOUND is not null, set *FOUND
4731 to 1 if KEY was found in SPEC, set it to 0 otherwise. */
4734 image_spec_value (spec
, key
, found
)
4735 Lisp_Object spec
, key
;
4740 xassert (valid_image_p (spec
));
4742 for (tail
= XCDR (spec
);
4743 CONSP (tail
) && CONSP (XCDR (tail
));
4744 tail
= XCDR (XCDR (tail
)))
4746 if (EQ (XCAR (tail
), key
))
4750 return XCAR (XCDR (tail
));
4760 DEFUN ("image-size", Fimage_size
, Simage_size
, 1, 3, 0,
4761 doc
: /* Return the size of image SPEC as pair (WIDTH . HEIGHT).
4762 PIXELS non-nil means return the size in pixels, otherwise return the
4763 size in canonical character units.
4764 FRAME is the frame on which the image will be displayed. FRAME nil
4765 or omitted means use the selected frame. */)
4766 (spec
, pixels
, frame
)
4767 Lisp_Object spec
, pixels
, frame
;
4772 if (valid_image_p (spec
))
4774 struct frame
*f
= check_x_frame (frame
);
4775 int id
= lookup_image (f
, spec
);
4776 struct image
*img
= IMAGE_FROM_ID (f
, id
);
4777 int width
= img
->width
+ 2 * img
->hmargin
;
4778 int height
= img
->height
+ 2 * img
->vmargin
;
4781 size
= Fcons (make_float ((double) width
/ FRAME_COLUMN_WIDTH (f
)),
4782 make_float ((double) height
/ FRAME_LINE_HEIGHT (f
)));
4784 size
= Fcons (make_number (width
), make_number (height
));
4787 error ("Invalid image specification");
4793 DEFUN ("image-mask-p", Fimage_mask_p
, Simage_mask_p
, 1, 2, 0,
4794 doc
: /* Return t if image SPEC has a mask bitmap.
4795 FRAME is the frame on which the image will be displayed. FRAME nil
4796 or omitted means use the selected frame. */)
4798 Lisp_Object spec
, frame
;
4803 if (valid_image_p (spec
))
4805 struct frame
*f
= check_x_frame (frame
);
4806 int id
= lookup_image (f
, spec
);
4807 struct image
*img
= IMAGE_FROM_ID (f
, id
);
4812 error ("Invalid image specification");
4819 /***********************************************************************
4820 Image type independent image structures
4821 ***********************************************************************/
4823 static struct image
*make_image
P_ ((Lisp_Object spec
, unsigned hash
));
4824 static void free_image
P_ ((struct frame
*f
, struct image
*img
));
4827 /* Allocate and return a new image structure for image specification
4828 SPEC. SPEC has a hash value of HASH. */
4830 static struct image
*
4831 make_image (spec
, hash
)
4835 struct image
*img
= (struct image
*) xmalloc (sizeof *img
);
4837 xassert (valid_image_p (spec
));
4838 bzero (img
, sizeof *img
);
4839 img
->type
= lookup_image_type (image_spec_value (spec
, QCtype
, NULL
));
4840 xassert (img
->type
!= NULL
);
4842 img
->data
.lisp_val
= Qnil
;
4843 img
->ascent
= DEFAULT_IMAGE_ASCENT
;
4849 /* Free image IMG which was used on frame F, including its resources. */
4858 struct image_cache
*c
= FRAME_X_IMAGE_CACHE (f
);
4860 /* Remove IMG from the hash table of its cache. */
4862 img
->prev
->next
= img
->next
;
4864 c
->buckets
[img
->hash
% IMAGE_CACHE_BUCKETS_SIZE
] = img
->next
;
4867 img
->next
->prev
= img
->prev
;
4869 c
->images
[img
->id
] = NULL
;
4871 /* Free resources, then free IMG. */
4872 img
->type
->free (f
, img
);
4878 /* Prepare image IMG for display on frame F. Must be called before
4879 drawing an image. */
4882 prepare_image_for_display (f
, img
)
4888 /* We're about to display IMG, so set its timestamp to `now'. */
4890 img
->timestamp
= EMACS_SECS (t
);
4892 /* If IMG doesn't have a pixmap yet, load it now, using the image
4893 type dependent loader function. */
4894 if (img
->pixmap
== None
&& !img
->load_failed_p
)
4895 img
->load_failed_p
= img
->type
->load (f
, img
) == 0;
4899 /* Value is the number of pixels for the ascent of image IMG when
4900 drawn in face FACE. */
4903 image_ascent (img
, face
)
4907 int height
= img
->height
+ img
->vmargin
;
4910 if (img
->ascent
== CENTERED_IMAGE_ASCENT
)
4913 /* This expression is arranged so that if the image can't be
4914 exactly centered, it will be moved slightly up. This is
4915 because a typical font is `top-heavy' (due to the presence
4916 uppercase letters), so the image placement should err towards
4917 being top-heavy too. It also just generally looks better. */
4918 ascent
= (height
+ face
->font
->ascent
- face
->font
->descent
+ 1) / 2;
4920 ascent
= height
/ 2;
4923 ascent
= height
* img
->ascent
/ 100.0;
4929 /* Image background colors. */
4931 static unsigned long
4932 four_corners_best (ximg
, width
, height
)
4934 unsigned long width
, height
;
4936 unsigned long corners
[4], best
;
4939 /* Get the colors at the corners of ximg. */
4940 corners
[0] = XGetPixel (ximg
, 0, 0);
4941 corners
[1] = XGetPixel (ximg
, width
- 1, 0);
4942 corners
[2] = XGetPixel (ximg
, width
- 1, height
- 1);
4943 corners
[3] = XGetPixel (ximg
, 0, height
- 1);
4945 /* Choose the most frequently found color as background. */
4946 for (i
= best_count
= 0; i
< 4; ++i
)
4950 for (j
= n
= 0; j
< 4; ++j
)
4951 if (corners
[i
] == corners
[j
])
4955 best
= corners
[i
], best_count
= n
;
4961 /* Return the `background' field of IMG. If IMG doesn't have one yet,
4962 it is guessed heuristically. If non-zero, XIMG is an existing XImage
4963 object to use for the heuristic. */
4966 image_background (img
, f
, ximg
)
4971 if (! img
->background_valid
)
4972 /* IMG doesn't have a background yet, try to guess a reasonable value. */
4974 int free_ximg
= !ximg
;
4977 ximg
= XGetImage (FRAME_X_DISPLAY (f
), img
->pixmap
,
4978 0, 0, img
->width
, img
->height
, ~0, ZPixmap
);
4980 img
->background
= four_corners_best (ximg
, img
->width
, img
->height
);
4983 XDestroyImage (ximg
);
4985 img
->background_valid
= 1;
4988 return img
->background
;
4991 /* Return the `background_transparent' field of IMG. If IMG doesn't
4992 have one yet, it is guessed heuristically. If non-zero, MASK is an
4993 existing XImage object to use for the heuristic. */
4996 image_background_transparent (img
, f
, mask
)
5001 if (! img
->background_transparent_valid
)
5002 /* IMG doesn't have a background yet, try to guess a reasonable value. */
5006 int free_mask
= !mask
;
5009 mask
= XGetImage (FRAME_X_DISPLAY (f
), img
->mask
,
5010 0, 0, img
->width
, img
->height
, ~0, ZPixmap
);
5012 img
->background_transparent
5013 = !four_corners_best (mask
, img
->width
, img
->height
);
5016 XDestroyImage (mask
);
5019 img
->background_transparent
= 0;
5021 img
->background_transparent_valid
= 1;
5024 return img
->background_transparent
;
5028 /***********************************************************************
5029 Helper functions for X image types
5030 ***********************************************************************/
5032 static void x_clear_image_1
P_ ((struct frame
*, struct image
*, int,
5034 static void x_clear_image
P_ ((struct frame
*f
, struct image
*img
));
5035 static unsigned long x_alloc_image_color
P_ ((struct frame
*f
,
5037 Lisp_Object color_name
,
5038 unsigned long dflt
));
5041 /* Clear X resources of image IMG on frame F. PIXMAP_P non-zero means
5042 free the pixmap if any. MASK_P non-zero means clear the mask
5043 pixmap if any. COLORS_P non-zero means free colors allocated for
5044 the image, if any. */
5047 x_clear_image_1 (f
, img
, pixmap_p
, mask_p
, colors_p
)
5050 int pixmap_p
, mask_p
, colors_p
;
5052 if (pixmap_p
&& img
->pixmap
)
5054 XFreePixmap (FRAME_X_DISPLAY (f
), img
->pixmap
);
5056 img
->background_valid
= 0;
5059 if (mask_p
&& img
->mask
)
5061 XFreePixmap (FRAME_X_DISPLAY (f
), img
->mask
);
5063 img
->background_transparent_valid
= 0;
5066 if (colors_p
&& img
->ncolors
)
5068 x_free_colors (f
, img
->colors
, img
->ncolors
);
5069 xfree (img
->colors
);
5075 /* Free X resources of image IMG which is used on frame F. */
5078 x_clear_image (f
, img
)
5083 x_clear_image_1 (f
, img
, 1, 1, 1);
5088 /* Allocate color COLOR_NAME for image IMG on frame F. If color
5089 cannot be allocated, use DFLT. Add a newly allocated color to
5090 IMG->colors, so that it can be freed again. Value is the pixel
5093 static unsigned long
5094 x_alloc_image_color (f
, img
, color_name
, dflt
)
5097 Lisp_Object color_name
;
5101 unsigned long result
;
5103 xassert (STRINGP (color_name
));
5105 if (x_defined_color (f
, SDATA (color_name
), &color
, 1))
5107 /* This isn't called frequently so we get away with simply
5108 reallocating the color vector to the needed size, here. */
5111 (unsigned long *) xrealloc (img
->colors
,
5112 img
->ncolors
* sizeof *img
->colors
);
5113 img
->colors
[img
->ncolors
- 1] = color
.pixel
;
5114 result
= color
.pixel
;
5124 /***********************************************************************
5126 ***********************************************************************/
5128 static void cache_image
P_ ((struct frame
*f
, struct image
*img
));
5129 static void postprocess_image
P_ ((struct frame
*, struct image
*));
5132 /* Return a new, initialized image cache that is allocated from the
5133 heap. Call free_image_cache to free an image cache. */
5135 struct image_cache
*
5138 struct image_cache
*c
= (struct image_cache
*) xmalloc (sizeof *c
);
5141 bzero (c
, sizeof *c
);
5143 c
->images
= (struct image
**) xmalloc (c
->size
* sizeof *c
->images
);
5144 size
= IMAGE_CACHE_BUCKETS_SIZE
* sizeof *c
->buckets
;
5145 c
->buckets
= (struct image
**) xmalloc (size
);
5146 bzero (c
->buckets
, size
);
5151 /* Free image cache of frame F. Be aware that X frames share images
5155 free_image_cache (f
)
5158 struct image_cache
*c
= FRAME_X_IMAGE_CACHE (f
);
5163 /* Cache should not be referenced by any frame when freed. */
5164 xassert (c
->refcount
== 0);
5166 for (i
= 0; i
< c
->used
; ++i
)
5167 free_image (f
, c
->images
[i
]);
5171 FRAME_X_IMAGE_CACHE (f
) = NULL
;
5176 /* Clear image cache of frame F. FORCE_P non-zero means free all
5177 images. FORCE_P zero means clear only images that haven't been
5178 displayed for some time. Should be called from time to time to
5179 reduce the number of loaded images. If image-eviction-seconds is
5180 non-nil, this frees images in the cache which weren't displayed for
5181 at least that many seconds. */
5184 clear_image_cache (f
, force_p
)
5188 struct image_cache
*c
= FRAME_X_IMAGE_CACHE (f
);
5190 if (c
&& INTEGERP (Vimage_cache_eviction_delay
))
5197 old
= EMACS_SECS (t
) - XFASTINT (Vimage_cache_eviction_delay
);
5199 /* Block input so that we won't be interrupted by a SIGIO
5200 while being in an inconsistent state. */
5203 for (i
= nfreed
= 0; i
< c
->used
; ++i
)
5205 struct image
*img
= c
->images
[i
];
5207 && (force_p
|| img
->timestamp
< old
))
5209 free_image (f
, img
);
5214 /* We may be clearing the image cache because, for example,
5215 Emacs was iconified for a longer period of time. In that
5216 case, current matrices may still contain references to
5217 images freed above. So, clear these matrices. */
5220 Lisp_Object tail
, frame
;
5222 FOR_EACH_FRAME (tail
, frame
)
5224 struct frame
*f
= XFRAME (frame
);
5226 && FRAME_X_IMAGE_CACHE (f
) == c
)
5227 clear_current_matrices (f
);
5230 ++windows_or_buffers_changed
;
5238 DEFUN ("clear-image-cache", Fclear_image_cache
, Sclear_image_cache
,
5240 doc
: /* Clear the image cache of FRAME.
5241 FRAME nil or omitted means use the selected frame.
5242 FRAME t means clear the image caches of all frames. */)
5250 FOR_EACH_FRAME (tail
, frame
)
5251 if (FRAME_X_P (XFRAME (frame
)))
5252 clear_image_cache (XFRAME (frame
), 1);
5255 clear_image_cache (check_x_frame (frame
), 1);
5261 /* Compute masks and transform image IMG on frame F, as specified
5262 by the image's specification, */
5265 postprocess_image (f
, img
)
5269 /* Manipulation of the image's mask. */
5272 Lisp_Object conversion
, spec
;
5277 /* `:heuristic-mask t'
5279 means build a mask heuristically.
5280 `:heuristic-mask (R G B)'
5281 `:mask (heuristic (R G B))'
5282 means build a mask from color (R G B) in the
5285 means remove a mask, if any. */
5287 mask
= image_spec_value (spec
, QCheuristic_mask
, NULL
);
5289 x_build_heuristic_mask (f
, img
, mask
);
5294 mask
= image_spec_value (spec
, QCmask
, &found_p
);
5296 if (EQ (mask
, Qheuristic
))
5297 x_build_heuristic_mask (f
, img
, Qt
);
5298 else if (CONSP (mask
)
5299 && EQ (XCAR (mask
), Qheuristic
))
5301 if (CONSP (XCDR (mask
)))
5302 x_build_heuristic_mask (f
, img
, XCAR (XCDR (mask
)));
5304 x_build_heuristic_mask (f
, img
, XCDR (mask
));
5306 else if (NILP (mask
) && found_p
&& img
->mask
)
5308 XFreePixmap (FRAME_X_DISPLAY (f
), img
->mask
);
5314 /* Should we apply an image transformation algorithm? */
5315 conversion
= image_spec_value (spec
, QCconversion
, NULL
);
5316 if (EQ (conversion
, Qdisabled
))
5317 x_disable_image (f
, img
);
5318 else if (EQ (conversion
, Qlaplace
))
5320 else if (EQ (conversion
, Qemboss
))
5322 else if (CONSP (conversion
)
5323 && EQ (XCAR (conversion
), Qedge_detection
))
5326 tem
= XCDR (conversion
);
5328 x_edge_detection (f
, img
,
5329 Fplist_get (tem
, QCmatrix
),
5330 Fplist_get (tem
, QCcolor_adjustment
));
5336 /* Return the id of image with Lisp specification SPEC on frame F.
5337 SPEC must be a valid Lisp image specification (see valid_image_p). */
5340 lookup_image (f
, spec
)
5344 struct image_cache
*c
= FRAME_X_IMAGE_CACHE (f
);
5348 struct gcpro gcpro1
;
5351 /* F must be a window-system frame, and SPEC must be a valid image
5353 xassert (FRAME_WINDOW_P (f
));
5354 xassert (valid_image_p (spec
));
5358 /* Look up SPEC in the hash table of the image cache. */
5359 hash
= sxhash (spec
, 0);
5360 i
= hash
% IMAGE_CACHE_BUCKETS_SIZE
;
5362 for (img
= c
->buckets
[i
]; img
; img
= img
->next
)
5363 if (img
->hash
== hash
&& !NILP (Fequal (img
->spec
, spec
)))
5366 /* If not found, create a new image and cache it. */
5369 extern Lisp_Object Qpostscript
;
5372 img
= make_image (spec
, hash
);
5373 cache_image (f
, img
);
5374 img
->load_failed_p
= img
->type
->load (f
, img
) == 0;
5376 /* If we can't load the image, and we don't have a width and
5377 height, use some arbitrary width and height so that we can
5378 draw a rectangle for it. */
5379 if (img
->load_failed_p
)
5383 value
= image_spec_value (spec
, QCwidth
, NULL
);
5384 img
->width
= (INTEGERP (value
)
5385 ? XFASTINT (value
) : DEFAULT_IMAGE_WIDTH
);
5386 value
= image_spec_value (spec
, QCheight
, NULL
);
5387 img
->height
= (INTEGERP (value
)
5388 ? XFASTINT (value
) : DEFAULT_IMAGE_HEIGHT
);
5392 /* Handle image type independent image attributes
5393 `:ascent ASCENT', `:margin MARGIN', `:relief RELIEF',
5394 `:background COLOR'. */
5395 Lisp_Object ascent
, margin
, relief
, bg
;
5397 ascent
= image_spec_value (spec
, QCascent
, NULL
);
5398 if (INTEGERP (ascent
))
5399 img
->ascent
= XFASTINT (ascent
);
5400 else if (EQ (ascent
, Qcenter
))
5401 img
->ascent
= CENTERED_IMAGE_ASCENT
;
5403 margin
= image_spec_value (spec
, QCmargin
, NULL
);
5404 if (INTEGERP (margin
) && XINT (margin
) >= 0)
5405 img
->vmargin
= img
->hmargin
= XFASTINT (margin
);
5406 else if (CONSP (margin
) && INTEGERP (XCAR (margin
))
5407 && INTEGERP (XCDR (margin
)))
5409 if (XINT (XCAR (margin
)) > 0)
5410 img
->hmargin
= XFASTINT (XCAR (margin
));
5411 if (XINT (XCDR (margin
)) > 0)
5412 img
->vmargin
= XFASTINT (XCDR (margin
));
5415 relief
= image_spec_value (spec
, QCrelief
, NULL
);
5416 if (INTEGERP (relief
))
5418 img
->relief
= XINT (relief
);
5419 img
->hmargin
+= abs (img
->relief
);
5420 img
->vmargin
+= abs (img
->relief
);
5423 if (! img
->background_valid
)
5425 bg
= image_spec_value (img
->spec
, QCbackground
, NULL
);
5429 = x_alloc_image_color (f
, img
, bg
,
5430 FRAME_BACKGROUND_PIXEL (f
));
5431 img
->background_valid
= 1;
5435 /* Do image transformations and compute masks, unless we
5436 don't have the image yet. */
5437 if (!EQ (*img
->type
->type
, Qpostscript
))
5438 postprocess_image (f
, img
);
5442 xassert (!interrupt_input_blocked
);
5445 /* We're using IMG, so set its timestamp to `now'. */
5446 EMACS_GET_TIME (now
);
5447 img
->timestamp
= EMACS_SECS (now
);
5451 /* Value is the image id. */
5456 /* Cache image IMG in the image cache of frame F. */
5459 cache_image (f
, img
)
5463 struct image_cache
*c
= FRAME_X_IMAGE_CACHE (f
);
5466 /* Find a free slot in c->images. */
5467 for (i
= 0; i
< c
->used
; ++i
)
5468 if (c
->images
[i
] == NULL
)
5471 /* If no free slot found, maybe enlarge c->images. */
5472 if (i
== c
->used
&& c
->used
== c
->size
)
5475 c
->images
= (struct image
**) xrealloc (c
->images
,
5476 c
->size
* sizeof *c
->images
);
5479 /* Add IMG to c->images, and assign IMG an id. */
5485 /* Add IMG to the cache's hash table. */
5486 i
= img
->hash
% IMAGE_CACHE_BUCKETS_SIZE
;
5487 img
->next
= c
->buckets
[i
];
5489 img
->next
->prev
= img
;
5491 c
->buckets
[i
] = img
;
5495 /* Call FN on every image in the image cache of frame F. Used to mark
5496 Lisp Objects in the image cache. */
5499 forall_images_in_image_cache (f
, fn
)
5501 void (*fn
) P_ ((struct image
*img
));
5503 if (FRAME_LIVE_P (f
) && FRAME_X_P (f
))
5505 struct image_cache
*c
= FRAME_X_IMAGE_CACHE (f
);
5509 for (i
= 0; i
< c
->used
; ++i
)
5518 /***********************************************************************
5520 ***********************************************************************/
5522 static int x_create_x_image_and_pixmap
P_ ((struct frame
*, int, int, int,
5523 XImage
**, Pixmap
*));
5524 static void x_destroy_x_image
P_ ((XImage
*));
5525 static void x_put_x_image
P_ ((struct frame
*, XImage
*, Pixmap
, int, int));
5528 /* Create an XImage and a pixmap of size WIDTH x HEIGHT for use on
5529 frame F. Set *XIMG and *PIXMAP to the XImage and Pixmap created.
5530 Set (*XIMG)->data to a raster of WIDTH x HEIGHT pixels allocated
5531 via xmalloc. Print error messages via image_error if an error
5532 occurs. Value is non-zero if successful. */
5535 x_create_x_image_and_pixmap (f
, width
, height
, depth
, ximg
, pixmap
)
5537 int width
, height
, depth
;
5541 Display
*display
= FRAME_X_DISPLAY (f
);
5542 Screen
*screen
= FRAME_X_SCREEN (f
);
5543 Window window
= FRAME_X_WINDOW (f
);
5545 xassert (interrupt_input_blocked
);
5548 depth
= DefaultDepthOfScreen (screen
);
5549 *ximg
= XCreateImage (display
, DefaultVisualOfScreen (screen
),
5550 depth
, ZPixmap
, 0, NULL
, width
, height
,
5551 depth
> 16 ? 32 : depth
> 8 ? 16 : 8, 0);
5554 image_error ("Unable to allocate X image", Qnil
, Qnil
);
5558 /* Allocate image raster. */
5559 (*ximg
)->data
= (char *) xmalloc ((*ximg
)->bytes_per_line
* height
);
5561 /* Allocate a pixmap of the same size. */
5562 *pixmap
= XCreatePixmap (display
, window
, width
, height
, depth
);
5563 if (*pixmap
== None
)
5565 x_destroy_x_image (*ximg
);
5567 image_error ("Unable to create X pixmap", Qnil
, Qnil
);
5575 /* Destroy XImage XIMG. Free XIMG->data. */
5578 x_destroy_x_image (ximg
)
5581 xassert (interrupt_input_blocked
);
5586 XDestroyImage (ximg
);
5591 /* Put XImage XIMG into pixmap PIXMAP on frame F. WIDTH and HEIGHT
5592 are width and height of both the image and pixmap. */
5595 x_put_x_image (f
, ximg
, pixmap
, width
, height
)
5603 xassert (interrupt_input_blocked
);
5604 gc
= XCreateGC (FRAME_X_DISPLAY (f
), pixmap
, 0, NULL
);
5605 XPutImage (FRAME_X_DISPLAY (f
), pixmap
, gc
, ximg
, 0, 0, 0, 0, width
, height
);
5606 XFreeGC (FRAME_X_DISPLAY (f
), gc
);
5611 /***********************************************************************
5613 ***********************************************************************/
5615 static Lisp_Object x_find_image_file
P_ ((Lisp_Object
));
5616 static char *slurp_file
P_ ((char *, int *));
5619 /* Find image file FILE. Look in data-directory, then
5620 x-bitmap-file-path. Value is the full name of the file found, or
5621 nil if not found. */
5624 x_find_image_file (file
)
5627 Lisp_Object file_found
, search_path
;
5628 struct gcpro gcpro1
, gcpro2
;
5632 search_path
= Fcons (Vdata_directory
, Vx_bitmap_file_path
);
5633 GCPRO2 (file_found
, search_path
);
5635 /* Try to find FILE in data-directory, then x-bitmap-file-path. */
5636 fd
= openp (search_path
, file
, Qnil
, &file_found
, Qnil
);
5648 /* Read FILE into memory. Value is a pointer to a buffer allocated
5649 with xmalloc holding FILE's contents. Value is null if an error
5650 occurred. *SIZE is set to the size of the file. */
5653 slurp_file (file
, size
)
5661 if (stat (file
, &st
) == 0
5662 && (fp
= fopen (file
, "r")) != NULL
5663 && (buf
= (char *) xmalloc (st
.st_size
),
5664 fread (buf
, 1, st
.st_size
, fp
) == st
.st_size
))
5685 /***********************************************************************
5687 ***********************************************************************/
5689 static int xbm_scan
P_ ((char **, char *, char *, int *));
5690 static int xbm_load
P_ ((struct frame
*f
, struct image
*img
));
5691 static int xbm_load_image
P_ ((struct frame
*f
, struct image
*img
,
5693 static int xbm_image_p
P_ ((Lisp_Object object
));
5694 static int xbm_read_bitmap_data
P_ ((char *, char *, int *, int *,
5696 static int xbm_file_p
P_ ((Lisp_Object
));
5699 /* Indices of image specification fields in xbm_format, below. */
5701 enum xbm_keyword_index
5719 /* Vector of image_keyword structures describing the format
5720 of valid XBM image specifications. */
5722 static struct image_keyword xbm_format
[XBM_LAST
] =
5724 {":type", IMAGE_SYMBOL_VALUE
, 1},
5725 {":file", IMAGE_STRING_VALUE
, 0},
5726 {":width", IMAGE_POSITIVE_INTEGER_VALUE
, 0},
5727 {":height", IMAGE_POSITIVE_INTEGER_VALUE
, 0},
5728 {":data", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
5729 {":foreground", IMAGE_STRING_OR_NIL_VALUE
, 0},
5730 {":background", IMAGE_STRING_OR_NIL_VALUE
, 0},
5731 {":ascent", IMAGE_ASCENT_VALUE
, 0},
5732 {":margin", IMAGE_POSITIVE_INTEGER_VALUE_OR_PAIR
, 0},
5733 {":relief", IMAGE_INTEGER_VALUE
, 0},
5734 {":conversion", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
5735 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
5736 {":mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0}
5739 /* Structure describing the image type XBM. */
5741 static struct image_type xbm_type
=
5750 /* Tokens returned from xbm_scan. */
5759 /* Return non-zero if OBJECT is a valid XBM-type image specification.
5760 A valid specification is a list starting with the symbol `image'
5761 The rest of the list is a property list which must contain an
5764 If the specification specifies a file to load, it must contain
5765 an entry `:file FILENAME' where FILENAME is a string.
5767 If the specification is for a bitmap loaded from memory it must
5768 contain `:width WIDTH', `:height HEIGHT', and `:data DATA', where
5769 WIDTH and HEIGHT are integers > 0. DATA may be:
5771 1. a string large enough to hold the bitmap data, i.e. it must
5772 have a size >= (WIDTH + 7) / 8 * HEIGHT
5774 2. a bool-vector of size >= WIDTH * HEIGHT
5776 3. a vector of strings or bool-vectors, one for each line of the
5779 4. A string containing an in-memory XBM file. WIDTH and HEIGHT
5780 may not be specified in this case because they are defined in the
5783 Both the file and data forms may contain the additional entries
5784 `:background COLOR' and `:foreground COLOR'. If not present,
5785 foreground and background of the frame on which the image is
5786 displayed is used. */
5789 xbm_image_p (object
)
5792 struct image_keyword kw
[XBM_LAST
];
5794 bcopy (xbm_format
, kw
, sizeof kw
);
5795 if (!parse_image_spec (object
, kw
, XBM_LAST
, Qxbm
))
5798 xassert (EQ (kw
[XBM_TYPE
].value
, Qxbm
));
5800 if (kw
[XBM_FILE
].count
)
5802 if (kw
[XBM_WIDTH
].count
|| kw
[XBM_HEIGHT
].count
|| kw
[XBM_DATA
].count
)
5805 else if (kw
[XBM_DATA
].count
&& xbm_file_p (kw
[XBM_DATA
].value
))
5807 /* In-memory XBM file. */
5808 if (kw
[XBM_WIDTH
].count
|| kw
[XBM_HEIGHT
].count
|| kw
[XBM_FILE
].count
)
5816 /* Entries for `:width', `:height' and `:data' must be present. */
5817 if (!kw
[XBM_WIDTH
].count
5818 || !kw
[XBM_HEIGHT
].count
5819 || !kw
[XBM_DATA
].count
)
5822 data
= kw
[XBM_DATA
].value
;
5823 width
= XFASTINT (kw
[XBM_WIDTH
].value
);
5824 height
= XFASTINT (kw
[XBM_HEIGHT
].value
);
5826 /* Check type of data, and width and height against contents of
5832 /* Number of elements of the vector must be >= height. */
5833 if (XVECTOR (data
)->size
< height
)
5836 /* Each string or bool-vector in data must be large enough
5837 for one line of the image. */
5838 for (i
= 0; i
< height
; ++i
)
5840 Lisp_Object elt
= XVECTOR (data
)->contents
[i
];
5845 < (width
+ BITS_PER_CHAR
- 1) / BITS_PER_CHAR
)
5848 else if (BOOL_VECTOR_P (elt
))
5850 if (XBOOL_VECTOR (elt
)->size
< width
)
5857 else if (STRINGP (data
))
5860 < (width
+ BITS_PER_CHAR
- 1) / BITS_PER_CHAR
* height
)
5863 else if (BOOL_VECTOR_P (data
))
5865 if (XBOOL_VECTOR (data
)->size
< width
* height
)
5876 /* Scan a bitmap file. FP is the stream to read from. Value is
5877 either an enumerator from enum xbm_token, or a character for a
5878 single-character token, or 0 at end of file. If scanning an
5879 identifier, store the lexeme of the identifier in SVAL. If
5880 scanning a number, store its value in *IVAL. */
5883 xbm_scan (s
, end
, sval
, ival
)
5892 /* Skip white space. */
5893 while (*s
< end
&& (c
= *(*s
)++, isspace (c
)))
5898 else if (isdigit (c
))
5900 int value
= 0, digit
;
5902 if (c
== '0' && *s
< end
)
5905 if (c
== 'x' || c
== 'X')
5912 else if (c
>= 'a' && c
<= 'f')
5913 digit
= c
- 'a' + 10;
5914 else if (c
>= 'A' && c
<= 'F')
5915 digit
= c
- 'A' + 10;
5918 value
= 16 * value
+ digit
;
5921 else if (isdigit (c
))
5925 && (c
= *(*s
)++, isdigit (c
)))
5926 value
= 8 * value
+ c
- '0';
5933 && (c
= *(*s
)++, isdigit (c
)))
5934 value
= 10 * value
+ c
- '0';
5942 else if (isalpha (c
) || c
== '_')
5946 && (c
= *(*s
)++, (isalnum (c
) || c
== '_')))
5953 else if (c
== '/' && **s
== '*')
5955 /* C-style comment. */
5957 while (**s
&& (**s
!= '*' || *(*s
+ 1) != '/'))
5970 /* Replacement for XReadBitmapFileData which isn't available under old
5971 X versions. CONTENTS is a pointer to a buffer to parse; END is the
5972 buffer's end. Set *WIDTH and *HEIGHT to the width and height of
5973 the image. Return in *DATA the bitmap data allocated with xmalloc.
5974 Value is non-zero if successful. DATA null means just test if
5975 CONTENTS looks like an in-memory XBM file. */
5978 xbm_read_bitmap_data (contents
, end
, width
, height
, data
)
5979 char *contents
, *end
;
5980 int *width
, *height
;
5981 unsigned char **data
;
5984 char buffer
[BUFSIZ
];
5987 int bytes_per_line
, i
, nbytes
;
5993 LA1 = xbm_scan (&s, end, buffer, &value)
5995 #define expect(TOKEN) \
5996 if (LA1 != (TOKEN)) \
6001 #define expect_ident(IDENT) \
6002 if (LA1 == XBM_TK_IDENT && strcmp (buffer, (IDENT)) == 0) \
6007 *width
= *height
= -1;
6010 LA1
= xbm_scan (&s
, end
, buffer
, &value
);
6012 /* Parse defines for width, height and hot-spots. */
6016 expect_ident ("define");
6017 expect (XBM_TK_IDENT
);
6019 if (LA1
== XBM_TK_NUMBER
);
6021 char *p
= strrchr (buffer
, '_');
6022 p
= p
? p
+ 1 : buffer
;
6023 if (strcmp (p
, "width") == 0)
6025 else if (strcmp (p
, "height") == 0)
6028 expect (XBM_TK_NUMBER
);
6031 if (*width
< 0 || *height
< 0)
6033 else if (data
== NULL
)
6036 /* Parse bits. Must start with `static'. */
6037 expect_ident ("static");
6038 if (LA1
== XBM_TK_IDENT
)
6040 if (strcmp (buffer
, "unsigned") == 0)
6043 expect_ident ("char");
6045 else if (strcmp (buffer
, "short") == 0)
6049 if (*width
% 16 && *width
% 16 < 9)
6052 else if (strcmp (buffer
, "char") == 0)
6060 expect (XBM_TK_IDENT
);
6066 bytes_per_line
= (*width
+ 7) / 8 + padding_p
;
6067 nbytes
= bytes_per_line
* *height
;
6068 p
= *data
= (char *) xmalloc (nbytes
);
6072 for (i
= 0; i
< nbytes
; i
+= 2)
6075 expect (XBM_TK_NUMBER
);
6078 if (!padding_p
|| ((i
+ 2) % bytes_per_line
))
6081 if (LA1
== ',' || LA1
== '}')
6089 for (i
= 0; i
< nbytes
; ++i
)
6092 expect (XBM_TK_NUMBER
);
6096 if (LA1
== ',' || LA1
== '}')
6121 /* Load XBM image IMG which will be displayed on frame F from buffer
6122 CONTENTS. END is the end of the buffer. Value is non-zero if
6126 xbm_load_image (f
, img
, contents
, end
)
6129 char *contents
, *end
;
6132 unsigned char *data
;
6135 rc
= xbm_read_bitmap_data (contents
, end
, &img
->width
, &img
->height
, &data
);
6138 int depth
= DefaultDepthOfScreen (FRAME_X_SCREEN (f
));
6139 unsigned long foreground
= FRAME_FOREGROUND_PIXEL (f
);
6140 unsigned long background
= FRAME_BACKGROUND_PIXEL (f
);
6143 xassert (img
->width
> 0 && img
->height
> 0);
6145 /* Get foreground and background colors, maybe allocate colors. */
6146 value
= image_spec_value (img
->spec
, QCforeground
, NULL
);
6148 foreground
= x_alloc_image_color (f
, img
, value
, foreground
);
6149 value
= image_spec_value (img
->spec
, QCbackground
, NULL
);
6152 background
= x_alloc_image_color (f
, img
, value
, background
);
6153 img
->background
= background
;
6154 img
->background_valid
= 1;
6158 = XCreatePixmapFromBitmapData (FRAME_X_DISPLAY (f
),
6161 img
->width
, img
->height
,
6162 foreground
, background
,
6166 if (img
->pixmap
== None
)
6168 x_clear_image (f
, img
);
6169 image_error ("Unable to create X pixmap for `%s'", img
->spec
, Qnil
);
6175 image_error ("Error loading XBM image `%s'", img
->spec
, Qnil
);
6181 /* Value is non-zero if DATA looks like an in-memory XBM file. */
6188 return (STRINGP (data
)
6189 && xbm_read_bitmap_data (SDATA (data
),
6196 /* Fill image IMG which is used on frame F with pixmap data. Value is
6197 non-zero if successful. */
6205 Lisp_Object file_name
;
6207 xassert (xbm_image_p (img
->spec
));
6209 /* If IMG->spec specifies a file name, create a non-file spec from it. */
6210 file_name
= image_spec_value (img
->spec
, QCfile
, NULL
);
6211 if (STRINGP (file_name
))
6216 struct gcpro gcpro1
;
6218 file
= x_find_image_file (file_name
);
6220 if (!STRINGP (file
))
6222 image_error ("Cannot find image file `%s'", file_name
, Qnil
);
6227 contents
= slurp_file (SDATA (file
), &size
);
6228 if (contents
== NULL
)
6230 image_error ("Error loading XBM image `%s'", img
->spec
, Qnil
);
6235 success_p
= xbm_load_image (f
, img
, contents
, contents
+ size
);
6240 struct image_keyword fmt
[XBM_LAST
];
6243 unsigned long foreground
= FRAME_FOREGROUND_PIXEL (f
);
6244 unsigned long background
= FRAME_BACKGROUND_PIXEL (f
);
6247 int in_memory_file_p
= 0;
6249 /* See if data looks like an in-memory XBM file. */
6250 data
= image_spec_value (img
->spec
, QCdata
, NULL
);
6251 in_memory_file_p
= xbm_file_p (data
);
6253 /* Parse the image specification. */
6254 bcopy (xbm_format
, fmt
, sizeof fmt
);
6255 parsed_p
= parse_image_spec (img
->spec
, fmt
, XBM_LAST
, Qxbm
);
6258 /* Get specified width, and height. */
6259 if (!in_memory_file_p
)
6261 img
->width
= XFASTINT (fmt
[XBM_WIDTH
].value
);
6262 img
->height
= XFASTINT (fmt
[XBM_HEIGHT
].value
);
6263 xassert (img
->width
> 0 && img
->height
> 0);
6266 /* Get foreground and background colors, maybe allocate colors. */
6267 if (fmt
[XBM_FOREGROUND
].count
6268 && STRINGP (fmt
[XBM_FOREGROUND
].value
))
6269 foreground
= x_alloc_image_color (f
, img
, fmt
[XBM_FOREGROUND
].value
,
6271 if (fmt
[XBM_BACKGROUND
].count
6272 && STRINGP (fmt
[XBM_BACKGROUND
].value
))
6273 background
= x_alloc_image_color (f
, img
, fmt
[XBM_BACKGROUND
].value
,
6276 if (in_memory_file_p
)
6277 success_p
= xbm_load_image (f
, img
, SDATA (data
),
6286 int nbytes
= (img
->width
+ BITS_PER_CHAR
- 1) / BITS_PER_CHAR
;
6288 p
= bits
= (char *) alloca (nbytes
* img
->height
);
6289 for (i
= 0; i
< img
->height
; ++i
, p
+= nbytes
)
6291 Lisp_Object line
= XVECTOR (data
)->contents
[i
];
6293 bcopy (SDATA (line
), p
, nbytes
);
6295 bcopy (XBOOL_VECTOR (line
)->data
, p
, nbytes
);
6298 else if (STRINGP (data
))
6299 bits
= SDATA (data
);
6301 bits
= XBOOL_VECTOR (data
)->data
;
6303 /* Create the pixmap. */
6304 depth
= DefaultDepthOfScreen (FRAME_X_SCREEN (f
));
6306 = XCreatePixmapFromBitmapData (FRAME_X_DISPLAY (f
),
6309 img
->width
, img
->height
,
6310 foreground
, background
,
6316 image_error ("Unable to create pixmap for XBM image `%s'",
6318 x_clear_image (f
, img
);
6328 /***********************************************************************
6330 ***********************************************************************/
6334 static int xpm_image_p
P_ ((Lisp_Object object
));
6335 static int xpm_load
P_ ((struct frame
*f
, struct image
*img
));
6336 static int xpm_valid_color_symbols_p
P_ ((Lisp_Object
));
6338 #include "X11/xpm.h"
6340 /* The symbol `xpm' identifying XPM-format images. */
6344 /* Indices of image specification fields in xpm_format, below. */
6346 enum xpm_keyword_index
6362 /* Vector of image_keyword structures describing the format
6363 of valid XPM image specifications. */
6365 static struct image_keyword xpm_format
[XPM_LAST
] =
6367 {":type", IMAGE_SYMBOL_VALUE
, 1},
6368 {":file", IMAGE_STRING_VALUE
, 0},
6369 {":data", IMAGE_STRING_VALUE
, 0},
6370 {":ascent", IMAGE_ASCENT_VALUE
, 0},
6371 {":margin", IMAGE_POSITIVE_INTEGER_VALUE_OR_PAIR
, 0},
6372 {":relief", IMAGE_INTEGER_VALUE
, 0},
6373 {":conversion", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
6374 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
6375 {":mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
6376 {":color-symbols", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
6377 {":background", IMAGE_STRING_OR_NIL_VALUE
, 0}
6380 /* Structure describing the image type XBM. */
6382 static struct image_type xpm_type
=
6392 /* Define ALLOC_XPM_COLORS if we can use Emacs' own color allocation
6393 functions for allocating image colors. Our own functions handle
6394 color allocation failures more gracefully than the ones on the XPM
6397 #if defined XpmAllocColor && defined XpmFreeColors && defined XpmColorClosure
6398 #define ALLOC_XPM_COLORS
6401 #ifdef ALLOC_XPM_COLORS
6403 static void xpm_init_color_cache
P_ ((struct frame
*, XpmAttributes
*));
6404 static void xpm_free_color_cache
P_ ((void));
6405 static int xpm_lookup_color
P_ ((struct frame
*, char *, XColor
*));
6406 static int xpm_color_bucket
P_ ((char *));
6407 static struct xpm_cached_color
*xpm_cache_color
P_ ((struct frame
*, char *,
6410 /* An entry in a hash table used to cache color definitions of named
6411 colors. This cache is necessary to speed up XPM image loading in
6412 case we do color allocations ourselves. Without it, we would need
6413 a call to XParseColor per pixel in the image. */
6415 struct xpm_cached_color
6417 /* Next in collision chain. */
6418 struct xpm_cached_color
*next
;
6420 /* Color definition (RGB and pixel color). */
6427 /* The hash table used for the color cache, and its bucket vector
6430 #define XPM_COLOR_CACHE_BUCKETS 1001
6431 struct xpm_cached_color
**xpm_color_cache
;
6433 /* Initialize the color cache. */
6436 xpm_init_color_cache (f
, attrs
)
6438 XpmAttributes
*attrs
;
6440 size_t nbytes
= XPM_COLOR_CACHE_BUCKETS
* sizeof *xpm_color_cache
;
6441 xpm_color_cache
= (struct xpm_cached_color
**) xmalloc (nbytes
);
6442 memset (xpm_color_cache
, 0, nbytes
);
6443 init_color_table ();
6445 if (attrs
->valuemask
& XpmColorSymbols
)
6450 for (i
= 0; i
< attrs
->numsymbols
; ++i
)
6451 if (XParseColor (FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
),
6452 attrs
->colorsymbols
[i
].value
, &color
))
6454 color
.pixel
= lookup_rgb_color (f
, color
.red
, color
.green
,
6456 xpm_cache_color (f
, attrs
->colorsymbols
[i
].name
, &color
, -1);
6462 /* Free the color cache. */
6465 xpm_free_color_cache ()
6467 struct xpm_cached_color
*p
, *next
;
6470 for (i
= 0; i
< XPM_COLOR_CACHE_BUCKETS
; ++i
)
6471 for (p
= xpm_color_cache
[i
]; p
; p
= next
)
6477 xfree (xpm_color_cache
);
6478 xpm_color_cache
= NULL
;
6479 free_color_table ();
6483 /* Return the bucket index for color named COLOR_NAME in the color
6487 xpm_color_bucket (color_name
)
6493 for (s
= color_name
; *s
; ++s
)
6495 return h
%= XPM_COLOR_CACHE_BUCKETS
;
6499 /* On frame F, cache values COLOR for color with name COLOR_NAME.
6500 BUCKET, if >= 0, is a precomputed bucket index. Value is the cache
6503 static struct xpm_cached_color
*
6504 xpm_cache_color (f
, color_name
, color
, bucket
)
6511 struct xpm_cached_color
*p
;
6514 bucket
= xpm_color_bucket (color_name
);
6516 nbytes
= sizeof *p
+ strlen (color_name
);
6517 p
= (struct xpm_cached_color
*) xmalloc (nbytes
);
6518 strcpy (p
->name
, color_name
);
6520 p
->next
= xpm_color_cache
[bucket
];
6521 xpm_color_cache
[bucket
] = p
;
6526 /* Look up color COLOR_NAME for frame F in the color cache. If found,
6527 return the cached definition in *COLOR. Otherwise, make a new
6528 entry in the cache and allocate the color. Value is zero if color
6529 allocation failed. */
6532 xpm_lookup_color (f
, color_name
, color
)
6537 struct xpm_cached_color
*p
;
6538 int h
= xpm_color_bucket (color_name
);
6540 for (p
= xpm_color_cache
[h
]; p
; p
= p
->next
)
6541 if (strcmp (p
->name
, color_name
) == 0)
6546 else if (XParseColor (FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
),
6549 color
->pixel
= lookup_rgb_color (f
, color
->red
, color
->green
,
6551 p
= xpm_cache_color (f
, color_name
, color
, h
);
6553 /* You get `opaque' at least from ImageMagick converting pbm to xpm
6554 with transparency, and it's useful. */
6555 else if (strcmp ("opaque", color_name
) == 0)
6557 bzero (color
, sizeof (XColor
)); /* Is this necessary/correct? */
6558 color
->pixel
= FRAME_FOREGROUND_PIXEL (f
);
6559 p
= xpm_cache_color (f
, color_name
, color
, h
);
6566 /* Callback for allocating color COLOR_NAME. Called from the XPM lib.
6567 CLOSURE is a pointer to the frame on which we allocate the
6568 color. Return in *COLOR the allocated color. Value is non-zero
6572 xpm_alloc_color (dpy
, cmap
, color_name
, color
, closure
)
6579 return xpm_lookup_color ((struct frame
*) closure
, color_name
, color
);
6583 /* Callback for freeing NPIXELS colors contained in PIXELS. CLOSURE
6584 is a pointer to the frame on which we allocate the color. Value is
6585 non-zero if successful. */
6588 xpm_free_colors (dpy
, cmap
, pixels
, npixels
, closure
)
6598 #endif /* ALLOC_XPM_COLORS */
6601 /* Value is non-zero if COLOR_SYMBOLS is a valid color symbols list
6602 for XPM images. Such a list must consist of conses whose car and
6606 xpm_valid_color_symbols_p (color_symbols
)
6607 Lisp_Object color_symbols
;
6609 while (CONSP (color_symbols
))
6611 Lisp_Object sym
= XCAR (color_symbols
);
6613 || !STRINGP (XCAR (sym
))
6614 || !STRINGP (XCDR (sym
)))
6616 color_symbols
= XCDR (color_symbols
);
6619 return NILP (color_symbols
);
6623 /* Value is non-zero if OBJECT is a valid XPM image specification. */
6626 xpm_image_p (object
)
6629 struct image_keyword fmt
[XPM_LAST
];
6630 bcopy (xpm_format
, fmt
, sizeof fmt
);
6631 return (parse_image_spec (object
, fmt
, XPM_LAST
, Qxpm
)
6632 /* Either `:file' or `:data' must be present. */
6633 && fmt
[XPM_FILE
].count
+ fmt
[XPM_DATA
].count
== 1
6634 /* Either no `:color-symbols' or it's a list of conses
6635 whose car and cdr are strings. */
6636 && (fmt
[XPM_COLOR_SYMBOLS
].count
== 0
6637 || xpm_valid_color_symbols_p (fmt
[XPM_COLOR_SYMBOLS
].value
)));
6641 /* Load image IMG which will be displayed on frame F. Value is
6642 non-zero if successful. */
6650 XpmAttributes attrs
;
6651 Lisp_Object specified_file
, color_symbols
;
6653 /* Configure the XPM lib. Use the visual of frame F. Allocate
6654 close colors. Return colors allocated. */
6655 bzero (&attrs
, sizeof attrs
);
6656 attrs
.visual
= FRAME_X_VISUAL (f
);
6657 attrs
.colormap
= FRAME_X_COLORMAP (f
);
6658 attrs
.valuemask
|= XpmVisual
;
6659 attrs
.valuemask
|= XpmColormap
;
6661 #ifdef ALLOC_XPM_COLORS
6662 /* Allocate colors with our own functions which handle
6663 failing color allocation more gracefully. */
6664 attrs
.color_closure
= f
;
6665 attrs
.alloc_color
= xpm_alloc_color
;
6666 attrs
.free_colors
= xpm_free_colors
;
6667 attrs
.valuemask
|= XpmAllocColor
| XpmFreeColors
| XpmColorClosure
;
6668 #else /* not ALLOC_XPM_COLORS */
6669 /* Let the XPM lib allocate colors. */
6670 attrs
.valuemask
|= XpmReturnAllocPixels
;
6671 #ifdef XpmAllocCloseColors
6672 attrs
.alloc_close_colors
= 1;
6673 attrs
.valuemask
|= XpmAllocCloseColors
;
6674 #else /* not XpmAllocCloseColors */
6675 attrs
.closeness
= 600;
6676 attrs
.valuemask
|= XpmCloseness
;
6677 #endif /* not XpmAllocCloseColors */
6678 #endif /* ALLOC_XPM_COLORS */
6680 /* If image specification contains symbolic color definitions, add
6681 these to `attrs'. */
6682 color_symbols
= image_spec_value (img
->spec
, QCcolor_symbols
, NULL
);
6683 if (CONSP (color_symbols
))
6686 XpmColorSymbol
*xpm_syms
;
6689 attrs
.valuemask
|= XpmColorSymbols
;
6691 /* Count number of symbols. */
6692 attrs
.numsymbols
= 0;
6693 for (tail
= color_symbols
; CONSP (tail
); tail
= XCDR (tail
))
6696 /* Allocate an XpmColorSymbol array. */
6697 size
= attrs
.numsymbols
* sizeof *xpm_syms
;
6698 xpm_syms
= (XpmColorSymbol
*) alloca (size
);
6699 bzero (xpm_syms
, size
);
6700 attrs
.colorsymbols
= xpm_syms
;
6702 /* Fill the color symbol array. */
6703 for (tail
= color_symbols
, i
= 0;
6705 ++i
, tail
= XCDR (tail
))
6707 Lisp_Object name
= XCAR (XCAR (tail
));
6708 Lisp_Object color
= XCDR (XCAR (tail
));
6709 xpm_syms
[i
].name
= (char *) alloca (SCHARS (name
) + 1);
6710 strcpy (xpm_syms
[i
].name
, SDATA (name
));
6711 xpm_syms
[i
].value
= (char *) alloca (SCHARS (color
) + 1);
6712 strcpy (xpm_syms
[i
].value
, SDATA (color
));
6716 /* Create a pixmap for the image, either from a file, or from a
6717 string buffer containing data in the same format as an XPM file. */
6718 #ifdef ALLOC_XPM_COLORS
6719 xpm_init_color_cache (f
, &attrs
);
6722 specified_file
= image_spec_value (img
->spec
, QCfile
, NULL
);
6723 if (STRINGP (specified_file
))
6725 Lisp_Object file
= x_find_image_file (specified_file
);
6726 if (!STRINGP (file
))
6728 image_error ("Cannot find image file `%s'", specified_file
, Qnil
);
6732 rc
= XpmReadFileToPixmap (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
6733 SDATA (file
), &img
->pixmap
, &img
->mask
,
6738 Lisp_Object buffer
= image_spec_value (img
->spec
, QCdata
, NULL
);
6739 rc
= XpmCreatePixmapFromBuffer (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
6741 &img
->pixmap
, &img
->mask
,
6745 if (rc
== XpmSuccess
)
6747 #ifdef ALLOC_XPM_COLORS
6748 img
->colors
= colors_in_color_table (&img
->ncolors
);
6749 #else /* not ALLOC_XPM_COLORS */
6752 img
->ncolors
= attrs
.nalloc_pixels
;
6753 img
->colors
= (unsigned long *) xmalloc (img
->ncolors
6754 * sizeof *img
->colors
);
6755 for (i
= 0; i
< attrs
.nalloc_pixels
; ++i
)
6757 img
->colors
[i
] = attrs
.alloc_pixels
[i
];
6758 #ifdef DEBUG_X_COLORS
6759 register_color (img
->colors
[i
]);
6762 #endif /* not ALLOC_XPM_COLORS */
6764 img
->width
= attrs
.width
;
6765 img
->height
= attrs
.height
;
6766 xassert (img
->width
> 0 && img
->height
> 0);
6768 /* The call to XpmFreeAttributes below frees attrs.alloc_pixels. */
6769 XpmFreeAttributes (&attrs
);
6776 image_error ("Error opening XPM file (%s)", img
->spec
, Qnil
);
6779 case XpmFileInvalid
:
6780 image_error ("Invalid XPM file (%s)", img
->spec
, Qnil
);
6784 image_error ("Out of memory (%s)", img
->spec
, Qnil
);
6787 case XpmColorFailed
:
6788 image_error ("Color allocation error (%s)", img
->spec
, Qnil
);
6792 image_error ("Unknown error (%s)", img
->spec
, Qnil
);
6797 #ifdef ALLOC_XPM_COLORS
6798 xpm_free_color_cache ();
6800 return rc
== XpmSuccess
;
6803 #endif /* HAVE_XPM != 0 */
6806 /***********************************************************************
6808 ***********************************************************************/
6810 /* An entry in the color table mapping an RGB color to a pixel color. */
6815 unsigned long pixel
;
6817 /* Next in color table collision list. */
6818 struct ct_color
*next
;
6821 /* The bucket vector size to use. Must be prime. */
6825 /* Value is a hash of the RGB color given by R, G, and B. */
6827 #define CT_HASH_RGB(R, G, B) (((R) << 16) ^ ((G) << 8) ^ (B))
6829 /* The color hash table. */
6831 struct ct_color
**ct_table
;
6833 /* Number of entries in the color table. */
6835 int ct_colors_allocated
;
6837 /* Initialize the color table. */
6842 int size
= CT_SIZE
* sizeof (*ct_table
);
6843 ct_table
= (struct ct_color
**) xmalloc (size
);
6844 bzero (ct_table
, size
);
6845 ct_colors_allocated
= 0;
6849 /* Free memory associated with the color table. */
6855 struct ct_color
*p
, *next
;
6857 for (i
= 0; i
< CT_SIZE
; ++i
)
6858 for (p
= ct_table
[i
]; p
; p
= next
)
6869 /* Value is a pixel color for RGB color R, G, B on frame F. If an
6870 entry for that color already is in the color table, return the
6871 pixel color of that entry. Otherwise, allocate a new color for R,
6872 G, B, and make an entry in the color table. */
6874 static unsigned long
6875 lookup_rgb_color (f
, r
, g
, b
)
6879 unsigned hash
= CT_HASH_RGB (r
, g
, b
);
6880 int i
= hash
% CT_SIZE
;
6882 struct x_display_info
*dpyinfo
;
6884 /* Handle TrueColor visuals specially, which improves performance by
6885 two orders of magnitude. Freeing colors on TrueColor visuals is
6886 a nop, and pixel colors specify RGB values directly. See also
6887 the Xlib spec, chapter 3.1. */
6888 dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
6889 if (dpyinfo
->red_bits
> 0)
6891 unsigned long pr
, pg
, pb
;
6893 /* Apply gamma-correction like normal color allocation does. */
6897 color
.red
= r
, color
.green
= g
, color
.blue
= b
;
6898 gamma_correct (f
, &color
);
6899 r
= color
.red
, g
= color
.green
, b
= color
.blue
;
6902 /* Scale down RGB values to the visual's bits per RGB, and shift
6903 them to the right position in the pixel color. Note that the
6904 original RGB values are 16-bit values, as usual in X. */
6905 pr
= (r
>> (16 - dpyinfo
->red_bits
)) << dpyinfo
->red_offset
;
6906 pg
= (g
>> (16 - dpyinfo
->green_bits
)) << dpyinfo
->green_offset
;
6907 pb
= (b
>> (16 - dpyinfo
->blue_bits
)) << dpyinfo
->blue_offset
;
6909 /* Assemble the pixel color. */
6910 return pr
| pg
| pb
;
6913 for (p
= ct_table
[i
]; p
; p
= p
->next
)
6914 if (p
->r
== r
&& p
->g
== g
&& p
->b
== b
)
6927 cmap
= FRAME_X_COLORMAP (f
);
6928 rc
= x_alloc_nearest_color (f
, cmap
, &color
);
6932 ++ct_colors_allocated
;
6934 p
= (struct ct_color
*) xmalloc (sizeof *p
);
6938 p
->pixel
= color
.pixel
;
6939 p
->next
= ct_table
[i
];
6943 return FRAME_FOREGROUND_PIXEL (f
);
6950 /* Look up pixel color PIXEL which is used on frame F in the color
6951 table. If not already present, allocate it. Value is PIXEL. */
6953 static unsigned long
6954 lookup_pixel_color (f
, pixel
)
6956 unsigned long pixel
;
6958 int i
= pixel
% CT_SIZE
;
6961 for (p
= ct_table
[i
]; p
; p
= p
->next
)
6962 if (p
->pixel
== pixel
)
6971 cmap
= FRAME_X_COLORMAP (f
);
6972 color
.pixel
= pixel
;
6973 x_query_color (f
, &color
);
6974 rc
= x_alloc_nearest_color (f
, cmap
, &color
);
6978 ++ct_colors_allocated
;
6980 p
= (struct ct_color
*) xmalloc (sizeof *p
);
6985 p
->next
= ct_table
[i
];
6989 return FRAME_FOREGROUND_PIXEL (f
);
6996 /* Value is a vector of all pixel colors contained in the color table,
6997 allocated via xmalloc. Set *N to the number of colors. */
6999 static unsigned long *
7000 colors_in_color_table (n
)
7005 unsigned long *colors
;
7007 if (ct_colors_allocated
== 0)
7014 colors
= (unsigned long *) xmalloc (ct_colors_allocated
7016 *n
= ct_colors_allocated
;
7018 for (i
= j
= 0; i
< CT_SIZE
; ++i
)
7019 for (p
= ct_table
[i
]; p
; p
= p
->next
)
7020 colors
[j
++] = p
->pixel
;
7028 /***********************************************************************
7030 ***********************************************************************/
7032 static XColor
*x_to_xcolors
P_ ((struct frame
*, struct image
*, int));
7033 static void x_from_xcolors
P_ ((struct frame
*, struct image
*, XColor
*));
7034 static void x_detect_edges
P_ ((struct frame
*, struct image
*, int[9], int));
7036 /* Non-zero means draw a cross on images having `:conversion
7039 int cross_disabled_images
;
7041 /* Edge detection matrices for different edge-detection
7044 static int emboss_matrix
[9] = {
7046 2, -1, 0, /* y - 1 */
7048 0, 1, -2 /* y + 1 */
7051 static int laplace_matrix
[9] = {
7053 1, 0, 0, /* y - 1 */
7055 0, 0, -1 /* y + 1 */
7058 /* Value is the intensity of the color whose red/green/blue values
7061 #define COLOR_INTENSITY(R, G, B) ((2 * (R) + 3 * (G) + (B)) / 6)
7064 /* On frame F, return an array of XColor structures describing image
7065 IMG->pixmap. Each XColor structure has its pixel color set. RGB_P
7066 non-zero means also fill the red/green/blue members of the XColor
7067 structures. Value is a pointer to the array of XColors structures,
7068 allocated with xmalloc; it must be freed by the caller. */
7071 x_to_xcolors (f
, img
, rgb_p
)
7080 colors
= (XColor
*) xmalloc (img
->width
* img
->height
* sizeof *colors
);
7082 /* Get the X image IMG->pixmap. */
7083 ximg
= XGetImage (FRAME_X_DISPLAY (f
), img
->pixmap
,
7084 0, 0, img
->width
, img
->height
, ~0, ZPixmap
);
7086 /* Fill the `pixel' members of the XColor array. I wished there
7087 were an easy and portable way to circumvent XGetPixel. */
7089 for (y
= 0; y
< img
->height
; ++y
)
7093 for (x
= 0; x
< img
->width
; ++x
, ++p
)
7094 p
->pixel
= XGetPixel (ximg
, x
, y
);
7097 x_query_colors (f
, row
, img
->width
);
7100 XDestroyImage (ximg
);
7105 /* Create IMG->pixmap from an array COLORS of XColor structures, whose
7106 RGB members are set. F is the frame on which this all happens.
7107 COLORS will be freed; an existing IMG->pixmap will be freed, too. */
7110 x_from_xcolors (f
, img
, colors
)
7120 init_color_table ();
7122 x_create_x_image_and_pixmap (f
, img
->width
, img
->height
, 0,
7125 for (y
= 0; y
< img
->height
; ++y
)
7126 for (x
= 0; x
< img
->width
; ++x
, ++p
)
7128 unsigned long pixel
;
7129 pixel
= lookup_rgb_color (f
, p
->red
, p
->green
, p
->blue
);
7130 XPutPixel (oimg
, x
, y
, pixel
);
7134 x_clear_image_1 (f
, img
, 1, 0, 1);
7136 x_put_x_image (f
, oimg
, pixmap
, img
->width
, img
->height
);
7137 x_destroy_x_image (oimg
);
7138 img
->pixmap
= pixmap
;
7139 img
->colors
= colors_in_color_table (&img
->ncolors
);
7140 free_color_table ();
7144 /* On frame F, perform edge-detection on image IMG.
7146 MATRIX is a nine-element array specifying the transformation
7147 matrix. See emboss_matrix for an example.
7149 COLOR_ADJUST is a color adjustment added to each pixel of the
7153 x_detect_edges (f
, img
, matrix
, color_adjust
)
7156 int matrix
[9], color_adjust
;
7158 XColor
*colors
= x_to_xcolors (f
, img
, 1);
7162 for (i
= sum
= 0; i
< 9; ++i
)
7163 sum
+= abs (matrix
[i
]);
7165 #define COLOR(A, X, Y) ((A) + (Y) * img->width + (X))
7167 new = (XColor
*) xmalloc (img
->width
* img
->height
* sizeof *new);
7169 for (y
= 0; y
< img
->height
; ++y
)
7171 p
= COLOR (new, 0, y
);
7172 p
->red
= p
->green
= p
->blue
= 0xffff/2;
7173 p
= COLOR (new, img
->width
- 1, y
);
7174 p
->red
= p
->green
= p
->blue
= 0xffff/2;
7177 for (x
= 1; x
< img
->width
- 1; ++x
)
7179 p
= COLOR (new, x
, 0);
7180 p
->red
= p
->green
= p
->blue
= 0xffff/2;
7181 p
= COLOR (new, x
, img
->height
- 1);
7182 p
->red
= p
->green
= p
->blue
= 0xffff/2;
7185 for (y
= 1; y
< img
->height
- 1; ++y
)
7187 p
= COLOR (new, 1, y
);
7189 for (x
= 1; x
< img
->width
- 1; ++x
, ++p
)
7191 int r
, g
, b
, y1
, x1
;
7194 for (y1
= y
- 1; y1
< y
+ 2; ++y1
)
7195 for (x1
= x
- 1; x1
< x
+ 2; ++x1
, ++i
)
7198 XColor
*t
= COLOR (colors
, x1
, y1
);
7199 r
+= matrix
[i
] * t
->red
;
7200 g
+= matrix
[i
] * t
->green
;
7201 b
+= matrix
[i
] * t
->blue
;
7204 r
= (r
/ sum
+ color_adjust
) & 0xffff;
7205 g
= (g
/ sum
+ color_adjust
) & 0xffff;
7206 b
= (b
/ sum
+ color_adjust
) & 0xffff;
7207 p
->red
= p
->green
= p
->blue
= COLOR_INTENSITY (r
, g
, b
);
7212 x_from_xcolors (f
, img
, new);
7218 /* Perform the pre-defined `emboss' edge-detection on image IMG
7226 x_detect_edges (f
, img
, emboss_matrix
, 0xffff / 2);
7230 /* Perform the pre-defined `laplace' edge-detection on image IMG
7238 x_detect_edges (f
, img
, laplace_matrix
, 45000);
7242 /* Perform edge-detection on image IMG on frame F, with specified
7243 transformation matrix MATRIX and color-adjustment COLOR_ADJUST.
7245 MATRIX must be either
7247 - a list of at least 9 numbers in row-major form
7248 - a vector of at least 9 numbers
7250 COLOR_ADJUST nil means use a default; otherwise it must be a
7254 x_edge_detection (f
, img
, matrix
, color_adjust
)
7257 Lisp_Object matrix
, color_adjust
;
7265 i
< 9 && CONSP (matrix
) && NUMBERP (XCAR (matrix
));
7266 ++i
, matrix
= XCDR (matrix
))
7267 trans
[i
] = XFLOATINT (XCAR (matrix
));
7269 else if (VECTORP (matrix
) && ASIZE (matrix
) >= 9)
7271 for (i
= 0; i
< 9 && NUMBERP (AREF (matrix
, i
)); ++i
)
7272 trans
[i
] = XFLOATINT (AREF (matrix
, i
));
7275 if (NILP (color_adjust
))
7276 color_adjust
= make_number (0xffff / 2);
7278 if (i
== 9 && NUMBERP (color_adjust
))
7279 x_detect_edges (f
, img
, trans
, (int) XFLOATINT (color_adjust
));
7283 /* Transform image IMG on frame F so that it looks disabled. */
7286 x_disable_image (f
, img
)
7290 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
7292 if (dpyinfo
->n_planes
>= 2)
7294 /* Color (or grayscale). Convert to gray, and equalize. Just
7295 drawing such images with a stipple can look very odd, so
7296 we're using this method instead. */
7297 XColor
*colors
= x_to_xcolors (f
, img
, 1);
7299 const int h
= 15000;
7300 const int l
= 30000;
7302 for (p
= colors
, end
= colors
+ img
->width
* img
->height
;
7306 int i
= COLOR_INTENSITY (p
->red
, p
->green
, p
->blue
);
7307 int i2
= (0xffff - h
- l
) * i
/ 0xffff + l
;
7308 p
->red
= p
->green
= p
->blue
= i2
;
7311 x_from_xcolors (f
, img
, colors
);
7314 /* Draw a cross over the disabled image, if we must or if we
7316 if (dpyinfo
->n_planes
< 2 || cross_disabled_images
)
7318 Display
*dpy
= FRAME_X_DISPLAY (f
);
7321 gc
= XCreateGC (dpy
, img
->pixmap
, 0, NULL
);
7322 XSetForeground (dpy
, gc
, BLACK_PIX_DEFAULT (f
));
7323 XDrawLine (dpy
, img
->pixmap
, gc
, 0, 0,
7324 img
->width
- 1, img
->height
- 1);
7325 XDrawLine (dpy
, img
->pixmap
, gc
, 0, img
->height
- 1,
7331 gc
= XCreateGC (dpy
, img
->mask
, 0, NULL
);
7332 XSetForeground (dpy
, gc
, WHITE_PIX_DEFAULT (f
));
7333 XDrawLine (dpy
, img
->mask
, gc
, 0, 0,
7334 img
->width
- 1, img
->height
- 1);
7335 XDrawLine (dpy
, img
->mask
, gc
, 0, img
->height
- 1,
7343 /* Build a mask for image IMG which is used on frame F. FILE is the
7344 name of an image file, for error messages. HOW determines how to
7345 determine the background color of IMG. If it is a list '(R G B)',
7346 with R, G, and B being integers >= 0, take that as the color of the
7347 background. Otherwise, determine the background color of IMG
7348 heuristically. Value is non-zero if successful. */
7351 x_build_heuristic_mask (f
, img
, how
)
7356 Display
*dpy
= FRAME_X_DISPLAY (f
);
7357 XImage
*ximg
, *mask_img
;
7358 int x
, y
, rc
, use_img_background
;
7359 unsigned long bg
= 0;
7363 XFreePixmap (FRAME_X_DISPLAY (f
), img
->mask
);
7365 img
->background_transparent_valid
= 0;
7368 /* Create an image and pixmap serving as mask. */
7369 rc
= x_create_x_image_and_pixmap (f
, img
->width
, img
->height
, 1,
7370 &mask_img
, &img
->mask
);
7374 /* Get the X image of IMG->pixmap. */
7375 ximg
= XGetImage (dpy
, img
->pixmap
, 0, 0, img
->width
, img
->height
,
7378 /* Determine the background color of ximg. If HOW is `(R G B)'
7379 take that as color. Otherwise, use the image's background color. */
7380 use_img_background
= 1;
7386 for (i
= 0; i
< 3 && CONSP (how
) && NATNUMP (XCAR (how
)); ++i
)
7388 rgb
[i
] = XFASTINT (XCAR (how
)) & 0xffff;
7392 if (i
== 3 && NILP (how
))
7394 char color_name
[30];
7395 sprintf (color_name
, "#%04x%04x%04x", rgb
[0], rgb
[1], rgb
[2]);
7396 bg
= x_alloc_image_color (f
, img
, build_string (color_name
), 0);
7397 use_img_background
= 0;
7401 if (use_img_background
)
7402 bg
= four_corners_best (ximg
, img
->width
, img
->height
);
7404 /* Set all bits in mask_img to 1 whose color in ximg is different
7405 from the background color bg. */
7406 for (y
= 0; y
< img
->height
; ++y
)
7407 for (x
= 0; x
< img
->width
; ++x
)
7408 XPutPixel (mask_img
, x
, y
, XGetPixel (ximg
, x
, y
) != bg
);
7410 /* Fill in the background_transparent field while we have the mask handy. */
7411 image_background_transparent (img
, f
, mask_img
);
7413 /* Put mask_img into img->mask. */
7414 x_put_x_image (f
, mask_img
, img
->mask
, img
->width
, img
->height
);
7415 x_destroy_x_image (mask_img
);
7416 XDestroyImage (ximg
);
7423 /***********************************************************************
7424 PBM (mono, gray, color)
7425 ***********************************************************************/
7427 static int pbm_image_p
P_ ((Lisp_Object object
));
7428 static int pbm_load
P_ ((struct frame
*f
, struct image
*img
));
7429 static int pbm_scan_number
P_ ((unsigned char **, unsigned char *));
7431 /* The symbol `pbm' identifying images of this type. */
7435 /* Indices of image specification fields in gs_format, below. */
7437 enum pbm_keyword_index
7453 /* Vector of image_keyword structures describing the format
7454 of valid user-defined image specifications. */
7456 static struct image_keyword pbm_format
[PBM_LAST
] =
7458 {":type", IMAGE_SYMBOL_VALUE
, 1},
7459 {":file", IMAGE_STRING_VALUE
, 0},
7460 {":data", IMAGE_STRING_VALUE
, 0},
7461 {":ascent", IMAGE_ASCENT_VALUE
, 0},
7462 {":margin", IMAGE_POSITIVE_INTEGER_VALUE_OR_PAIR
, 0},
7463 {":relief", IMAGE_INTEGER_VALUE
, 0},
7464 {":conversion", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
7465 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
7466 {":mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
7467 {":foreground", IMAGE_STRING_OR_NIL_VALUE
, 0},
7468 {":background", IMAGE_STRING_OR_NIL_VALUE
, 0}
7471 /* Structure describing the image type `pbm'. */
7473 static struct image_type pbm_type
=
7483 /* Return non-zero if OBJECT is a valid PBM image specification. */
7486 pbm_image_p (object
)
7489 struct image_keyword fmt
[PBM_LAST
];
7491 bcopy (pbm_format
, fmt
, sizeof fmt
);
7493 if (!parse_image_spec (object
, fmt
, PBM_LAST
, Qpbm
))
7496 /* Must specify either :data or :file. */
7497 return fmt
[PBM_DATA
].count
+ fmt
[PBM_FILE
].count
== 1;
7501 /* Scan a decimal number from *S and return it. Advance *S while
7502 reading the number. END is the end of the string. Value is -1 at
7506 pbm_scan_number (s
, end
)
7507 unsigned char **s
, *end
;
7509 int c
= 0, val
= -1;
7513 /* Skip white-space. */
7514 while (*s
< end
&& (c
= *(*s
)++, isspace (c
)))
7519 /* Skip comment to end of line. */
7520 while (*s
< end
&& (c
= *(*s
)++, c
!= '\n'))
7523 else if (isdigit (c
))
7525 /* Read decimal number. */
7527 while (*s
< end
&& (c
= *(*s
)++, isdigit (c
)))
7528 val
= 10 * val
+ c
- '0';
7539 /* Load PBM image IMG for use on frame F. */
7547 int width
, height
, max_color_idx
= 0;
7549 Lisp_Object file
, specified_file
;
7550 enum {PBM_MONO
, PBM_GRAY
, PBM_COLOR
} type
;
7551 struct gcpro gcpro1
;
7552 unsigned char *contents
= NULL
;
7553 unsigned char *end
, *p
;
7556 specified_file
= image_spec_value (img
->spec
, QCfile
, NULL
);
7560 if (STRINGP (specified_file
))
7562 file
= x_find_image_file (specified_file
);
7563 if (!STRINGP (file
))
7565 image_error ("Cannot find image file `%s'", specified_file
, Qnil
);
7570 contents
= slurp_file (SDATA (file
), &size
);
7571 if (contents
== NULL
)
7573 image_error ("Error reading `%s'", file
, Qnil
);
7579 end
= contents
+ size
;
7584 data
= image_spec_value (img
->spec
, QCdata
, NULL
);
7586 end
= p
+ SBYTES (data
);
7589 /* Check magic number. */
7590 if (end
- p
< 2 || *p
++ != 'P')
7592 image_error ("Not a PBM image: `%s'", img
->spec
, Qnil
);
7602 raw_p
= 0, type
= PBM_MONO
;
7606 raw_p
= 0, type
= PBM_GRAY
;
7610 raw_p
= 0, type
= PBM_COLOR
;
7614 raw_p
= 1, type
= PBM_MONO
;
7618 raw_p
= 1, type
= PBM_GRAY
;
7622 raw_p
= 1, type
= PBM_COLOR
;
7626 image_error ("Not a PBM image: `%s'", img
->spec
, Qnil
);
7630 /* Read width, height, maximum color-component. Characters
7631 starting with `#' up to the end of a line are ignored. */
7632 width
= pbm_scan_number (&p
, end
);
7633 height
= pbm_scan_number (&p
, end
);
7635 if (type
!= PBM_MONO
)
7637 max_color_idx
= pbm_scan_number (&p
, end
);
7638 if (raw_p
&& max_color_idx
> 255)
7639 max_color_idx
= 255;
7644 || (type
!= PBM_MONO
&& max_color_idx
< 0))
7647 if (!x_create_x_image_and_pixmap (f
, width
, height
, 0,
7648 &ximg
, &img
->pixmap
))
7651 /* Initialize the color hash table. */
7652 init_color_table ();
7654 if (type
== PBM_MONO
)
7657 struct image_keyword fmt
[PBM_LAST
];
7658 unsigned long fg
= FRAME_FOREGROUND_PIXEL (f
);
7659 unsigned long bg
= FRAME_BACKGROUND_PIXEL (f
);
7661 /* Parse the image specification. */
7662 bcopy (pbm_format
, fmt
, sizeof fmt
);
7663 parse_image_spec (img
->spec
, fmt
, PBM_LAST
, Qpbm
);
7665 /* Get foreground and background colors, maybe allocate colors. */
7666 if (fmt
[PBM_FOREGROUND
].count
7667 && STRINGP (fmt
[PBM_FOREGROUND
].value
))
7668 fg
= x_alloc_image_color (f
, img
, fmt
[PBM_FOREGROUND
].value
, fg
);
7669 if (fmt
[PBM_BACKGROUND
].count
7670 && STRINGP (fmt
[PBM_BACKGROUND
].value
))
7672 bg
= x_alloc_image_color (f
, img
, fmt
[PBM_BACKGROUND
].value
, bg
);
7673 img
->background
= bg
;
7674 img
->background_valid
= 1;
7677 for (y
= 0; y
< height
; ++y
)
7678 for (x
= 0; x
< width
; ++x
)
7688 g
= pbm_scan_number (&p
, end
);
7690 XPutPixel (ximg
, x
, y
, g
? fg
: bg
);
7695 for (y
= 0; y
< height
; ++y
)
7696 for (x
= 0; x
< width
; ++x
)
7700 if (type
== PBM_GRAY
)
7701 r
= g
= b
= raw_p
? *p
++ : pbm_scan_number (&p
, end
);
7710 r
= pbm_scan_number (&p
, end
);
7711 g
= pbm_scan_number (&p
, end
);
7712 b
= pbm_scan_number (&p
, end
);
7715 if (r
< 0 || g
< 0 || b
< 0)
7719 XDestroyImage (ximg
);
7720 image_error ("Invalid pixel value in image `%s'",
7725 /* RGB values are now in the range 0..max_color_idx.
7726 Scale this to the range 0..0xffff supported by X. */
7727 r
= (double) r
* 65535 / max_color_idx
;
7728 g
= (double) g
* 65535 / max_color_idx
;
7729 b
= (double) b
* 65535 / max_color_idx
;
7730 XPutPixel (ximg
, x
, y
, lookup_rgb_color (f
, r
, g
, b
));
7734 /* Store in IMG->colors the colors allocated for the image, and
7735 free the color table. */
7736 img
->colors
= colors_in_color_table (&img
->ncolors
);
7737 free_color_table ();
7739 /* Maybe fill in the background field while we have ximg handy. */
7740 if (NILP (image_spec_value (img
->spec
, QCbackground
, NULL
)))
7741 IMAGE_BACKGROUND (img
, f
, ximg
);
7743 /* Put the image into a pixmap. */
7744 x_put_x_image (f
, ximg
, img
->pixmap
, width
, height
);
7745 x_destroy_x_image (ximg
);
7748 img
->height
= height
;
7757 /***********************************************************************
7759 ***********************************************************************/
7763 #if defined HAVE_LIBPNG_PNG_H
7764 # include <libpng/png.h>
7769 /* Function prototypes. */
7771 static int png_image_p
P_ ((Lisp_Object object
));
7772 static int png_load
P_ ((struct frame
*f
, struct image
*img
));
7774 /* The symbol `png' identifying images of this type. */
7778 /* Indices of image specification fields in png_format, below. */
7780 enum png_keyword_index
7795 /* Vector of image_keyword structures describing the format
7796 of valid user-defined image specifications. */
7798 static struct image_keyword png_format
[PNG_LAST
] =
7800 {":type", IMAGE_SYMBOL_VALUE
, 1},
7801 {":data", IMAGE_STRING_VALUE
, 0},
7802 {":file", IMAGE_STRING_VALUE
, 0},
7803 {":ascent", IMAGE_ASCENT_VALUE
, 0},
7804 {":margin", IMAGE_POSITIVE_INTEGER_VALUE_OR_PAIR
, 0},
7805 {":relief", IMAGE_INTEGER_VALUE
, 0},
7806 {":conversion", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
7807 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
7808 {":mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
7809 {":background", IMAGE_STRING_OR_NIL_VALUE
, 0}
7812 /* Structure describing the image type `png'. */
7814 static struct image_type png_type
=
7824 /* Return non-zero if OBJECT is a valid PNG image specification. */
7827 png_image_p (object
)
7830 struct image_keyword fmt
[PNG_LAST
];
7831 bcopy (png_format
, fmt
, sizeof fmt
);
7833 if (!parse_image_spec (object
, fmt
, PNG_LAST
, Qpng
))
7836 /* Must specify either the :data or :file keyword. */
7837 return fmt
[PNG_FILE
].count
+ fmt
[PNG_DATA
].count
== 1;
7841 /* Error and warning handlers installed when the PNG library
7845 my_png_error (png_ptr
, msg
)
7846 png_struct
*png_ptr
;
7849 xassert (png_ptr
!= NULL
);
7850 image_error ("PNG error: %s", build_string (msg
), Qnil
);
7851 longjmp (png_ptr
->jmpbuf
, 1);
7856 my_png_warning (png_ptr
, msg
)
7857 png_struct
*png_ptr
;
7860 xassert (png_ptr
!= NULL
);
7861 image_error ("PNG warning: %s", build_string (msg
), Qnil
);
7864 /* Memory source for PNG decoding. */
7866 struct png_memory_storage
7868 unsigned char *bytes
; /* The data */
7869 size_t len
; /* How big is it? */
7870 int index
; /* Where are we? */
7874 /* Function set as reader function when reading PNG image from memory.
7875 PNG_PTR is a pointer to the PNG control structure. Copy LENGTH
7876 bytes from the input to DATA. */
7879 png_read_from_memory (png_ptr
, data
, length
)
7880 png_structp png_ptr
;
7884 struct png_memory_storage
*tbr
7885 = (struct png_memory_storage
*) png_get_io_ptr (png_ptr
);
7887 if (length
> tbr
->len
- tbr
->index
)
7888 png_error (png_ptr
, "Read error");
7890 bcopy (tbr
->bytes
+ tbr
->index
, data
, length
);
7891 tbr
->index
= tbr
->index
+ length
;
7894 /* Load PNG image IMG for use on frame F. Value is non-zero if
7902 Lisp_Object file
, specified_file
;
7903 Lisp_Object specified_data
;
7905 XImage
*ximg
, *mask_img
= NULL
;
7906 struct gcpro gcpro1
;
7907 png_struct
*png_ptr
= NULL
;
7908 png_info
*info_ptr
= NULL
, *end_info
= NULL
;
7909 FILE *volatile fp
= NULL
;
7911 png_byte
* volatile pixels
= NULL
;
7912 png_byte
** volatile rows
= NULL
;
7913 png_uint_32 width
, height
;
7914 int bit_depth
, color_type
, interlace_type
;
7916 png_uint_32 row_bytes
;
7918 double screen_gamma
;
7919 struct png_memory_storage tbr
; /* Data to be read */
7921 /* Find out what file to load. */
7922 specified_file
= image_spec_value (img
->spec
, QCfile
, NULL
);
7923 specified_data
= image_spec_value (img
->spec
, QCdata
, NULL
);
7927 if (NILP (specified_data
))
7929 file
= x_find_image_file (specified_file
);
7930 if (!STRINGP (file
))
7932 image_error ("Cannot find image file `%s'", specified_file
, Qnil
);
7937 /* Open the image file. */
7938 fp
= fopen (SDATA (file
), "rb");
7941 image_error ("Cannot open image file `%s'", file
, Qnil
);
7947 /* Check PNG signature. */
7948 if (fread (sig
, 1, sizeof sig
, fp
) != sizeof sig
7949 || !png_check_sig (sig
, sizeof sig
))
7951 image_error ("Not a PNG file: `%s'", file
, Qnil
);
7959 /* Read from memory. */
7960 tbr
.bytes
= SDATA (specified_data
);
7961 tbr
.len
= SBYTES (specified_data
);
7964 /* Check PNG signature. */
7965 if (tbr
.len
< sizeof sig
7966 || !png_check_sig (tbr
.bytes
, sizeof sig
))
7968 image_error ("Not a PNG image: `%s'", img
->spec
, Qnil
);
7973 /* Need to skip past the signature. */
7974 tbr
.bytes
+= sizeof (sig
);
7977 /* Initialize read and info structs for PNG lib. */
7978 png_ptr
= png_create_read_struct (PNG_LIBPNG_VER_STRING
, NULL
,
7979 my_png_error
, my_png_warning
);
7982 if (fp
) fclose (fp
);
7987 info_ptr
= png_create_info_struct (png_ptr
);
7990 png_destroy_read_struct (&png_ptr
, NULL
, NULL
);
7991 if (fp
) fclose (fp
);
7996 end_info
= png_create_info_struct (png_ptr
);
7999 png_destroy_read_struct (&png_ptr
, &info_ptr
, NULL
);
8000 if (fp
) fclose (fp
);
8005 /* Set error jump-back. We come back here when the PNG library
8006 detects an error. */
8007 if (setjmp (png_ptr
->jmpbuf
))
8011 png_destroy_read_struct (&png_ptr
, &info_ptr
, &end_info
);
8014 if (fp
) fclose (fp
);
8019 /* Read image info. */
8020 if (!NILP (specified_data
))
8021 png_set_read_fn (png_ptr
, (void *) &tbr
, png_read_from_memory
);
8023 png_init_io (png_ptr
, fp
);
8025 png_set_sig_bytes (png_ptr
, sizeof sig
);
8026 png_read_info (png_ptr
, info_ptr
);
8027 png_get_IHDR (png_ptr
, info_ptr
, &width
, &height
, &bit_depth
, &color_type
,
8028 &interlace_type
, NULL
, NULL
);
8030 /* If image contains simply transparency data, we prefer to
8031 construct a clipping mask. */
8032 if (png_get_valid (png_ptr
, info_ptr
, PNG_INFO_tRNS
))
8037 /* This function is easier to write if we only have to handle
8038 one data format: RGB or RGBA with 8 bits per channel. Let's
8039 transform other formats into that format. */
8041 /* Strip more than 8 bits per channel. */
8042 if (bit_depth
== 16)
8043 png_set_strip_16 (png_ptr
);
8045 /* Expand data to 24 bit RGB, or 8 bit grayscale, with alpha channel
8047 png_set_expand (png_ptr
);
8049 /* Convert grayscale images to RGB. */
8050 if (color_type
== PNG_COLOR_TYPE_GRAY
8051 || color_type
== PNG_COLOR_TYPE_GRAY_ALPHA
)
8052 png_set_gray_to_rgb (png_ptr
);
8054 screen_gamma
= (f
->gamma
? 1 / f
->gamma
/ 0.45455 : 2.2);
8056 #if 0 /* Avoid double gamma correction for PNG images. */
8057 { /* Tell the PNG lib to handle gamma correction for us. */
8060 #if defined(PNG_READ_sRGB_SUPPORTED) || defined(PNG_WRITE_sRGB_SUPPORTED)
8061 if (png_get_sRGB (png_ptr
, info_ptr
, &intent
))
8062 /* The libpng documentation says this is right in this case. */
8063 png_set_gamma (png_ptr
, screen_gamma
, 0.45455);
8066 if (png_get_gAMA (png_ptr
, info_ptr
, &image_gamma
))
8067 /* Image contains gamma information. */
8068 png_set_gamma (png_ptr
, screen_gamma
, image_gamma
);
8070 /* Use the standard default for the image gamma. */
8071 png_set_gamma (png_ptr
, screen_gamma
, 0.45455);
8075 /* Handle alpha channel by combining the image with a background
8076 color. Do this only if a real alpha channel is supplied. For
8077 simple transparency, we prefer a clipping mask. */
8080 png_color_16
*image_bg
;
8081 Lisp_Object specified_bg
8082 = image_spec_value (img
->spec
, QCbackground
, NULL
);
8084 if (STRINGP (specified_bg
))
8085 /* The user specified `:background', use that. */
8088 if (x_defined_color (f
, SDATA (specified_bg
), &color
, 0))
8090 png_color_16 user_bg
;
8092 bzero (&user_bg
, sizeof user_bg
);
8093 user_bg
.red
= color
.red
;
8094 user_bg
.green
= color
.green
;
8095 user_bg
.blue
= color
.blue
;
8097 png_set_background (png_ptr
, &user_bg
,
8098 PNG_BACKGROUND_GAMMA_SCREEN
, 0, 1.0);
8101 else if (png_get_bKGD (png_ptr
, info_ptr
, &image_bg
))
8102 /* Image contains a background color with which to
8103 combine the image. */
8104 png_set_background (png_ptr
, image_bg
,
8105 PNG_BACKGROUND_GAMMA_FILE
, 1, 1.0);
8108 /* Image does not contain a background color with which
8109 to combine the image data via an alpha channel. Use
8110 the frame's background instead. */
8113 png_color_16 frame_background
;
8115 cmap
= FRAME_X_COLORMAP (f
);
8116 color
.pixel
= FRAME_BACKGROUND_PIXEL (f
);
8117 x_query_color (f
, &color
);
8119 bzero (&frame_background
, sizeof frame_background
);
8120 frame_background
.red
= color
.red
;
8121 frame_background
.green
= color
.green
;
8122 frame_background
.blue
= color
.blue
;
8124 png_set_background (png_ptr
, &frame_background
,
8125 PNG_BACKGROUND_GAMMA_SCREEN
, 0, 1.0);
8129 /* Update info structure. */
8130 png_read_update_info (png_ptr
, info_ptr
);
8132 /* Get number of channels. Valid values are 1 for grayscale images
8133 and images with a palette, 2 for grayscale images with transparency
8134 information (alpha channel), 3 for RGB images, and 4 for RGB
8135 images with alpha channel, i.e. RGBA. If conversions above were
8136 sufficient we should only have 3 or 4 channels here. */
8137 channels
= png_get_channels (png_ptr
, info_ptr
);
8138 xassert (channels
== 3 || channels
== 4);
8140 /* Number of bytes needed for one row of the image. */
8141 row_bytes
= png_get_rowbytes (png_ptr
, info_ptr
);
8143 /* Allocate memory for the image. */
8144 pixels
= (png_byte
*) xmalloc (row_bytes
* height
* sizeof *pixels
);
8145 rows
= (png_byte
**) xmalloc (height
* sizeof *rows
);
8146 for (i
= 0; i
< height
; ++i
)
8147 rows
[i
] = pixels
+ i
* row_bytes
;
8149 /* Read the entire image. */
8150 png_read_image (png_ptr
, rows
);
8151 png_read_end (png_ptr
, info_ptr
);
8158 /* Create the X image and pixmap. */
8159 if (!x_create_x_image_and_pixmap (f
, width
, height
, 0, &ximg
,
8163 /* Create an image and pixmap serving as mask if the PNG image
8164 contains an alpha channel. */
8167 && !x_create_x_image_and_pixmap (f
, width
, height
, 1,
8168 &mask_img
, &img
->mask
))
8170 x_destroy_x_image (ximg
);
8171 XFreePixmap (FRAME_X_DISPLAY (f
), img
->pixmap
);
8176 /* Fill the X image and mask from PNG data. */
8177 init_color_table ();
8179 for (y
= 0; y
< height
; ++y
)
8181 png_byte
*p
= rows
[y
];
8183 for (x
= 0; x
< width
; ++x
)
8190 XPutPixel (ximg
, x
, y
, lookup_rgb_color (f
, r
, g
, b
));
8192 /* An alpha channel, aka mask channel, associates variable
8193 transparency with an image. Where other image formats
8194 support binary transparency---fully transparent or fully
8195 opaque---PNG allows up to 254 levels of partial transparency.
8196 The PNG library implements partial transparency by combining
8197 the image with a specified background color.
8199 I'm not sure how to handle this here nicely: because the
8200 background on which the image is displayed may change, for
8201 real alpha channel support, it would be necessary to create
8202 a new image for each possible background.
8204 What I'm doing now is that a mask is created if we have
8205 boolean transparency information. Otherwise I'm using
8206 the frame's background color to combine the image with. */
8211 XPutPixel (mask_img
, x
, y
, *p
> 0);
8217 if (NILP (image_spec_value (img
->spec
, QCbackground
, NULL
)))
8218 /* Set IMG's background color from the PNG image, unless the user
8222 if (png_get_bKGD (png_ptr
, info_ptr
, &bg
))
8224 img
->background
= lookup_rgb_color (f
, bg
->red
, bg
->green
, bg
->blue
);
8225 img
->background_valid
= 1;
8229 /* Remember colors allocated for this image. */
8230 img
->colors
= colors_in_color_table (&img
->ncolors
);
8231 free_color_table ();
8234 png_destroy_read_struct (&png_ptr
, &info_ptr
, &end_info
);
8239 img
->height
= height
;
8241 /* Maybe fill in the background field while we have ximg handy. */
8242 IMAGE_BACKGROUND (img
, f
, ximg
);
8244 /* Put the image into the pixmap, then free the X image and its buffer. */
8245 x_put_x_image (f
, ximg
, img
->pixmap
, width
, height
);
8246 x_destroy_x_image (ximg
);
8248 /* Same for the mask. */
8251 /* Fill in the background_transparent field while we have the mask
8253 image_background_transparent (img
, f
, mask_img
);
8255 x_put_x_image (f
, mask_img
, img
->mask
, img
->width
, img
->height
);
8256 x_destroy_x_image (mask_img
);
8263 #endif /* HAVE_PNG != 0 */
8267 /***********************************************************************
8269 ***********************************************************************/
8273 /* Work around a warning about HAVE_STDLIB_H being redefined in
8275 #ifdef HAVE_STDLIB_H
8276 #define HAVE_STDLIB_H_1
8277 #undef HAVE_STDLIB_H
8278 #endif /* HAVE_STLIB_H */
8280 #include <jpeglib.h>
8284 #ifdef HAVE_STLIB_H_1
8285 #define HAVE_STDLIB_H 1
8288 static int jpeg_image_p
P_ ((Lisp_Object object
));
8289 static int jpeg_load
P_ ((struct frame
*f
, struct image
*img
));
8291 /* The symbol `jpeg' identifying images of this type. */
8295 /* Indices of image specification fields in gs_format, below. */
8297 enum jpeg_keyword_index
8306 JPEG_HEURISTIC_MASK
,
8312 /* Vector of image_keyword structures describing the format
8313 of valid user-defined image specifications. */
8315 static struct image_keyword jpeg_format
[JPEG_LAST
] =
8317 {":type", IMAGE_SYMBOL_VALUE
, 1},
8318 {":data", IMAGE_STRING_VALUE
, 0},
8319 {":file", IMAGE_STRING_VALUE
, 0},
8320 {":ascent", IMAGE_ASCENT_VALUE
, 0},
8321 {":margin", IMAGE_POSITIVE_INTEGER_VALUE_OR_PAIR
, 0},
8322 {":relief", IMAGE_INTEGER_VALUE
, 0},
8323 {":conversions", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
8324 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
8325 {":mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
8326 {":background", IMAGE_STRING_OR_NIL_VALUE
, 0}
8329 /* Structure describing the image type `jpeg'. */
8331 static struct image_type jpeg_type
=
8341 /* Return non-zero if OBJECT is a valid JPEG image specification. */
8344 jpeg_image_p (object
)
8347 struct image_keyword fmt
[JPEG_LAST
];
8349 bcopy (jpeg_format
, fmt
, sizeof fmt
);
8351 if (!parse_image_spec (object
, fmt
, JPEG_LAST
, Qjpeg
))
8354 /* Must specify either the :data or :file keyword. */
8355 return fmt
[JPEG_FILE
].count
+ fmt
[JPEG_DATA
].count
== 1;
8359 struct my_jpeg_error_mgr
8361 struct jpeg_error_mgr pub
;
8362 jmp_buf setjmp_buffer
;
8367 my_error_exit (cinfo
)
8370 struct my_jpeg_error_mgr
*mgr
= (struct my_jpeg_error_mgr
*) cinfo
->err
;
8371 longjmp (mgr
->setjmp_buffer
, 1);
8375 /* Init source method for JPEG data source manager. Called by
8376 jpeg_read_header() before any data is actually read. See
8377 libjpeg.doc from the JPEG lib distribution. */
8380 our_init_source (cinfo
)
8381 j_decompress_ptr cinfo
;
8386 /* Fill input buffer method for JPEG data source manager. Called
8387 whenever more data is needed. We read the whole image in one step,
8388 so this only adds a fake end of input marker at the end. */
8391 our_fill_input_buffer (cinfo
)
8392 j_decompress_ptr cinfo
;
8394 /* Insert a fake EOI marker. */
8395 struct jpeg_source_mgr
*src
= cinfo
->src
;
8396 static JOCTET buffer
[2];
8398 buffer
[0] = (JOCTET
) 0xFF;
8399 buffer
[1] = (JOCTET
) JPEG_EOI
;
8401 src
->next_input_byte
= buffer
;
8402 src
->bytes_in_buffer
= 2;
8407 /* Method to skip over NUM_BYTES bytes in the image data. CINFO->src
8408 is the JPEG data source manager. */
8411 our_skip_input_data (cinfo
, num_bytes
)
8412 j_decompress_ptr cinfo
;
8415 struct jpeg_source_mgr
*src
= (struct jpeg_source_mgr
*) cinfo
->src
;
8419 if (num_bytes
> src
->bytes_in_buffer
)
8420 ERREXIT (cinfo
, JERR_INPUT_EOF
);
8422 src
->bytes_in_buffer
-= num_bytes
;
8423 src
->next_input_byte
+= num_bytes
;
8428 /* Method to terminate data source. Called by
8429 jpeg_finish_decompress() after all data has been processed. */
8432 our_term_source (cinfo
)
8433 j_decompress_ptr cinfo
;
8438 /* Set up the JPEG lib for reading an image from DATA which contains
8439 LEN bytes. CINFO is the decompression info structure created for
8440 reading the image. */
8443 jpeg_memory_src (cinfo
, data
, len
)
8444 j_decompress_ptr cinfo
;
8448 struct jpeg_source_mgr
*src
;
8450 if (cinfo
->src
== NULL
)
8452 /* First time for this JPEG object? */
8453 cinfo
->src
= (struct jpeg_source_mgr
*)
8454 (*cinfo
->mem
->alloc_small
) ((j_common_ptr
) cinfo
, JPOOL_PERMANENT
,
8455 sizeof (struct jpeg_source_mgr
));
8456 src
= (struct jpeg_source_mgr
*) cinfo
->src
;
8457 src
->next_input_byte
= data
;
8460 src
= (struct jpeg_source_mgr
*) cinfo
->src
;
8461 src
->init_source
= our_init_source
;
8462 src
->fill_input_buffer
= our_fill_input_buffer
;
8463 src
->skip_input_data
= our_skip_input_data
;
8464 src
->resync_to_restart
= jpeg_resync_to_restart
; /* Use default method. */
8465 src
->term_source
= our_term_source
;
8466 src
->bytes_in_buffer
= len
;
8467 src
->next_input_byte
= data
;
8471 /* Load image IMG for use on frame F. Patterned after example.c
8472 from the JPEG lib. */
8479 struct jpeg_decompress_struct cinfo
;
8480 struct my_jpeg_error_mgr mgr
;
8481 Lisp_Object file
, specified_file
;
8482 Lisp_Object specified_data
;
8483 FILE * volatile fp
= NULL
;
8485 int row_stride
, x
, y
;
8486 XImage
*ximg
= NULL
;
8488 unsigned long *colors
;
8490 struct gcpro gcpro1
;
8492 /* Open the JPEG file. */
8493 specified_file
= image_spec_value (img
->spec
, QCfile
, NULL
);
8494 specified_data
= image_spec_value (img
->spec
, QCdata
, NULL
);
8498 if (NILP (specified_data
))
8500 file
= x_find_image_file (specified_file
);
8501 if (!STRINGP (file
))
8503 image_error ("Cannot find image file `%s'", specified_file
, Qnil
);
8508 fp
= fopen (SDATA (file
), "r");
8511 image_error ("Cannot open `%s'", file
, Qnil
);
8517 /* Customize libjpeg's error handling to call my_error_exit when an
8518 error is detected. This function will perform a longjmp. */
8519 cinfo
.err
= jpeg_std_error (&mgr
.pub
);
8520 mgr
.pub
.error_exit
= my_error_exit
;
8522 if ((rc
= setjmp (mgr
.setjmp_buffer
)) != 0)
8526 /* Called from my_error_exit. Display a JPEG error. */
8527 char buffer
[JMSG_LENGTH_MAX
];
8528 cinfo
.err
->format_message ((j_common_ptr
) &cinfo
, buffer
);
8529 image_error ("Error reading JPEG image `%s': %s", img
->spec
,
8530 build_string (buffer
));
8533 /* Close the input file and destroy the JPEG object. */
8535 fclose ((FILE *) fp
);
8536 jpeg_destroy_decompress (&cinfo
);
8538 /* If we already have an XImage, free that. */
8539 x_destroy_x_image (ximg
);
8541 /* Free pixmap and colors. */
8542 x_clear_image (f
, img
);
8548 /* Create the JPEG decompression object. Let it read from fp.
8549 Read the JPEG image header. */
8550 jpeg_create_decompress (&cinfo
);
8552 if (NILP (specified_data
))
8553 jpeg_stdio_src (&cinfo
, (FILE *) fp
);
8555 jpeg_memory_src (&cinfo
, SDATA (specified_data
),
8556 SBYTES (specified_data
));
8558 jpeg_read_header (&cinfo
, TRUE
);
8560 /* Customize decompression so that color quantization will be used.
8561 Start decompression. */
8562 cinfo
.quantize_colors
= TRUE
;
8563 jpeg_start_decompress (&cinfo
);
8564 width
= img
->width
= cinfo
.output_width
;
8565 height
= img
->height
= cinfo
.output_height
;
8567 /* Create X image and pixmap. */
8568 if (!x_create_x_image_and_pixmap (f
, width
, height
, 0, &ximg
, &img
->pixmap
))
8569 longjmp (mgr
.setjmp_buffer
, 2);
8571 /* Allocate colors. When color quantization is used,
8572 cinfo.actual_number_of_colors has been set with the number of
8573 colors generated, and cinfo.colormap is a two-dimensional array
8574 of color indices in the range 0..cinfo.actual_number_of_colors.
8575 No more than 255 colors will be generated. */
8579 if (cinfo
.out_color_components
> 2)
8580 ir
= 0, ig
= 1, ib
= 2;
8581 else if (cinfo
.out_color_components
> 1)
8582 ir
= 0, ig
= 1, ib
= 0;
8584 ir
= 0, ig
= 0, ib
= 0;
8586 /* Use the color table mechanism because it handles colors that
8587 cannot be allocated nicely. Such colors will be replaced with
8588 a default color, and we don't have to care about which colors
8589 can be freed safely, and which can't. */
8590 init_color_table ();
8591 colors
= (unsigned long *) alloca (cinfo
.actual_number_of_colors
8594 for (i
= 0; i
< cinfo
.actual_number_of_colors
; ++i
)
8596 /* Multiply RGB values with 255 because X expects RGB values
8597 in the range 0..0xffff. */
8598 int r
= cinfo
.colormap
[ir
][i
] << 8;
8599 int g
= cinfo
.colormap
[ig
][i
] << 8;
8600 int b
= cinfo
.colormap
[ib
][i
] << 8;
8601 colors
[i
] = lookup_rgb_color (f
, r
, g
, b
);
8604 /* Remember those colors actually allocated. */
8605 img
->colors
= colors_in_color_table (&img
->ncolors
);
8606 free_color_table ();
8610 row_stride
= width
* cinfo
.output_components
;
8611 buffer
= cinfo
.mem
->alloc_sarray ((j_common_ptr
) &cinfo
, JPOOL_IMAGE
,
8613 for (y
= 0; y
< height
; ++y
)
8615 jpeg_read_scanlines (&cinfo
, buffer
, 1);
8616 for (x
= 0; x
< cinfo
.output_width
; ++x
)
8617 XPutPixel (ximg
, x
, y
, colors
[buffer
[0][x
]]);
8621 jpeg_finish_decompress (&cinfo
);
8622 jpeg_destroy_decompress (&cinfo
);
8624 fclose ((FILE *) fp
);
8626 /* Maybe fill in the background field while we have ximg handy. */
8627 if (NILP (image_spec_value (img
->spec
, QCbackground
, NULL
)))
8628 IMAGE_BACKGROUND (img
, f
, ximg
);
8630 /* Put the image into the pixmap. */
8631 x_put_x_image (f
, ximg
, img
->pixmap
, width
, height
);
8632 x_destroy_x_image (ximg
);
8637 #endif /* HAVE_JPEG */
8641 /***********************************************************************
8643 ***********************************************************************/
8649 static int tiff_image_p
P_ ((Lisp_Object object
));
8650 static int tiff_load
P_ ((struct frame
*f
, struct image
*img
));
8652 /* The symbol `tiff' identifying images of this type. */
8656 /* Indices of image specification fields in tiff_format, below. */
8658 enum tiff_keyword_index
8667 TIFF_HEURISTIC_MASK
,
8673 /* Vector of image_keyword structures describing the format
8674 of valid user-defined image specifications. */
8676 static struct image_keyword tiff_format
[TIFF_LAST
] =
8678 {":type", IMAGE_SYMBOL_VALUE
, 1},
8679 {":data", IMAGE_STRING_VALUE
, 0},
8680 {":file", IMAGE_STRING_VALUE
, 0},
8681 {":ascent", IMAGE_ASCENT_VALUE
, 0},
8682 {":margin", IMAGE_POSITIVE_INTEGER_VALUE_OR_PAIR
, 0},
8683 {":relief", IMAGE_INTEGER_VALUE
, 0},
8684 {":conversions", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
8685 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
8686 {":mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
8687 {":background", IMAGE_STRING_OR_NIL_VALUE
, 0}
8690 /* Structure describing the image type `tiff'. */
8692 static struct image_type tiff_type
=
8702 /* Return non-zero if OBJECT is a valid TIFF image specification. */
8705 tiff_image_p (object
)
8708 struct image_keyword fmt
[TIFF_LAST
];
8709 bcopy (tiff_format
, fmt
, sizeof fmt
);
8711 if (!parse_image_spec (object
, fmt
, TIFF_LAST
, Qtiff
))
8714 /* Must specify either the :data or :file keyword. */
8715 return fmt
[TIFF_FILE
].count
+ fmt
[TIFF_DATA
].count
== 1;
8719 /* Reading from a memory buffer for TIFF images Based on the PNG
8720 memory source, but we have to provide a lot of extra functions.
8723 We really only need to implement read and seek, but I am not
8724 convinced that the TIFF library is smart enough not to destroy
8725 itself if we only hand it the function pointers we need to
8730 unsigned char *bytes
;
8738 tiff_read_from_memory (data
, buf
, size
)
8743 tiff_memory_source
*src
= (tiff_memory_source
*) data
;
8745 if (size
> src
->len
- src
->index
)
8747 bcopy (src
->bytes
+ src
->index
, buf
, size
);
8754 tiff_write_from_memory (data
, buf
, size
)
8764 tiff_seek_in_memory (data
, off
, whence
)
8769 tiff_memory_source
*src
= (tiff_memory_source
*) data
;
8774 case SEEK_SET
: /* Go from beginning of source. */
8778 case SEEK_END
: /* Go from end of source. */
8779 idx
= src
->len
+ off
;
8782 case SEEK_CUR
: /* Go from current position. */
8783 idx
= src
->index
+ off
;
8786 default: /* Invalid `whence'. */
8790 if (idx
> src
->len
|| idx
< 0)
8799 tiff_close_memory (data
)
8808 tiff_mmap_memory (data
, pbase
, psize
)
8813 /* It is already _IN_ memory. */
8819 tiff_unmap_memory (data
, base
, size
)
8824 /* We don't need to do this. */
8829 tiff_size_of_memory (data
)
8832 return ((tiff_memory_source
*) data
)->len
;
8837 tiff_error_handler (title
, format
, ap
)
8838 const char *title
, *format
;
8844 len
= sprintf (buf
, "TIFF error: %s ", title
);
8845 vsprintf (buf
+ len
, format
, ap
);
8846 add_to_log (buf
, Qnil
, Qnil
);
8851 tiff_warning_handler (title
, format
, ap
)
8852 const char *title
, *format
;
8858 len
= sprintf (buf
, "TIFF warning: %s ", title
);
8859 vsprintf (buf
+ len
, format
, ap
);
8860 add_to_log (buf
, Qnil
, Qnil
);
8864 /* Load TIFF image IMG for use on frame F. Value is non-zero if
8872 Lisp_Object file
, specified_file
;
8873 Lisp_Object specified_data
;
8875 int width
, height
, x
, y
;
8879 struct gcpro gcpro1
;
8880 tiff_memory_source memsrc
;
8882 specified_file
= image_spec_value (img
->spec
, QCfile
, NULL
);
8883 specified_data
= image_spec_value (img
->spec
, QCdata
, NULL
);
8887 TIFFSetErrorHandler (tiff_error_handler
);
8888 TIFFSetWarningHandler (tiff_warning_handler
);
8890 if (NILP (specified_data
))
8892 /* Read from a file */
8893 file
= x_find_image_file (specified_file
);
8894 if (!STRINGP (file
))
8896 image_error ("Cannot find image file `%s'", file
, Qnil
);
8901 /* Try to open the image file. */
8902 tiff
= TIFFOpen (SDATA (file
), "r");
8905 image_error ("Cannot open `%s'", file
, Qnil
);
8912 /* Memory source! */
8913 memsrc
.bytes
= SDATA (specified_data
);
8914 memsrc
.len
= SBYTES (specified_data
);
8917 tiff
= TIFFClientOpen ("memory_source", "r", &memsrc
,
8918 (TIFFReadWriteProc
) tiff_read_from_memory
,
8919 (TIFFReadWriteProc
) tiff_write_from_memory
,
8920 tiff_seek_in_memory
,
8922 tiff_size_of_memory
,
8928 image_error ("Cannot open memory source for `%s'", img
->spec
, Qnil
);
8934 /* Get width and height of the image, and allocate a raster buffer
8935 of width x height 32-bit values. */
8936 TIFFGetField (tiff
, TIFFTAG_IMAGEWIDTH
, &width
);
8937 TIFFGetField (tiff
, TIFFTAG_IMAGELENGTH
, &height
);
8938 buf
= (uint32
*) xmalloc (width
* height
* sizeof *buf
);
8940 rc
= TIFFReadRGBAImage (tiff
, width
, height
, buf
, 0);
8944 image_error ("Error reading TIFF image `%s'", img
->spec
, Qnil
);
8950 /* Create the X image and pixmap. */
8951 if (!x_create_x_image_and_pixmap (f
, width
, height
, 0, &ximg
, &img
->pixmap
))
8958 /* Initialize the color table. */
8959 init_color_table ();
8961 /* Process the pixel raster. Origin is in the lower-left corner. */
8962 for (y
= 0; y
< height
; ++y
)
8964 uint32
*row
= buf
+ y
* width
;
8966 for (x
= 0; x
< width
; ++x
)
8968 uint32 abgr
= row
[x
];
8969 int r
= TIFFGetR (abgr
) << 8;
8970 int g
= TIFFGetG (abgr
) << 8;
8971 int b
= TIFFGetB (abgr
) << 8;
8972 XPutPixel (ximg
, x
, height
- 1 - y
, lookup_rgb_color (f
, r
, g
, b
));
8976 /* Remember the colors allocated for the image. Free the color table. */
8977 img
->colors
= colors_in_color_table (&img
->ncolors
);
8978 free_color_table ();
8981 img
->height
= height
;
8983 /* Maybe fill in the background field while we have ximg handy. */
8984 if (NILP (image_spec_value (img
->spec
, QCbackground
, NULL
)))
8985 IMAGE_BACKGROUND (img
, f
, ximg
);
8987 /* Put the image into the pixmap, then free the X image and its buffer. */
8988 x_put_x_image (f
, ximg
, img
->pixmap
, width
, height
);
8989 x_destroy_x_image (ximg
);
8996 #endif /* HAVE_TIFF != 0 */
9000 /***********************************************************************
9002 ***********************************************************************/
9006 #include <gif_lib.h>
9008 static int gif_image_p
P_ ((Lisp_Object object
));
9009 static int gif_load
P_ ((struct frame
*f
, struct image
*img
));
9011 /* The symbol `gif' identifying images of this type. */
9015 /* Indices of image specification fields in gif_format, below. */
9017 enum gif_keyword_index
9033 /* Vector of image_keyword structures describing the format
9034 of valid user-defined image specifications. */
9036 static struct image_keyword gif_format
[GIF_LAST
] =
9038 {":type", IMAGE_SYMBOL_VALUE
, 1},
9039 {":data", IMAGE_STRING_VALUE
, 0},
9040 {":file", IMAGE_STRING_VALUE
, 0},
9041 {":ascent", IMAGE_ASCENT_VALUE
, 0},
9042 {":margin", IMAGE_POSITIVE_INTEGER_VALUE_OR_PAIR
, 0},
9043 {":relief", IMAGE_INTEGER_VALUE
, 0},
9044 {":conversion", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
9045 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
9046 {":mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
9047 {":image", IMAGE_NON_NEGATIVE_INTEGER_VALUE
, 0},
9048 {":background", IMAGE_STRING_OR_NIL_VALUE
, 0}
9051 /* Structure describing the image type `gif'. */
9053 static struct image_type gif_type
=
9063 /* Return non-zero if OBJECT is a valid GIF image specification. */
9066 gif_image_p (object
)
9069 struct image_keyword fmt
[GIF_LAST
];
9070 bcopy (gif_format
, fmt
, sizeof fmt
);
9072 if (!parse_image_spec (object
, fmt
, GIF_LAST
, Qgif
))
9075 /* Must specify either the :data or :file keyword. */
9076 return fmt
[GIF_FILE
].count
+ fmt
[GIF_DATA
].count
== 1;
9080 /* Reading a GIF image from memory
9081 Based on the PNG memory stuff to a certain extent. */
9085 unsigned char *bytes
;
9092 /* Make the current memory source available to gif_read_from_memory.
9093 It's done this way because not all versions of libungif support
9094 a UserData field in the GifFileType structure. */
9095 static gif_memory_source
*current_gif_memory_src
;
9098 gif_read_from_memory (file
, buf
, len
)
9103 gif_memory_source
*src
= current_gif_memory_src
;
9105 if (len
> src
->len
- src
->index
)
9108 bcopy (src
->bytes
+ src
->index
, buf
, len
);
9114 /* Load GIF image IMG for use on frame F. Value is non-zero if
9122 Lisp_Object file
, specified_file
;
9123 Lisp_Object specified_data
;
9124 int rc
, width
, height
, x
, y
, i
;
9126 ColorMapObject
*gif_color_map
;
9127 unsigned long pixel_colors
[256];
9129 struct gcpro gcpro1
;
9131 int ino
, image_left
, image_top
, image_width
, image_height
;
9132 gif_memory_source memsrc
;
9133 unsigned char *raster
;
9135 specified_file
= image_spec_value (img
->spec
, QCfile
, NULL
);
9136 specified_data
= image_spec_value (img
->spec
, QCdata
, NULL
);
9140 if (NILP (specified_data
))
9142 file
= x_find_image_file (specified_file
);
9143 if (!STRINGP (file
))
9145 image_error ("Cannot find image file `%s'", specified_file
, Qnil
);
9150 /* Open the GIF file. */
9151 gif
= DGifOpenFileName (SDATA (file
));
9154 image_error ("Cannot open `%s'", file
, Qnil
);
9161 /* Read from memory! */
9162 current_gif_memory_src
= &memsrc
;
9163 memsrc
.bytes
= SDATA (specified_data
);
9164 memsrc
.len
= SBYTES (specified_data
);
9167 gif
= DGifOpen (&memsrc
, gif_read_from_memory
);
9170 image_error ("Cannot open memory source `%s'", img
->spec
, Qnil
);
9176 /* Read entire contents. */
9177 rc
= DGifSlurp (gif
);
9178 if (rc
== GIF_ERROR
)
9180 image_error ("Error reading `%s'", img
->spec
, Qnil
);
9181 DGifCloseFile (gif
);
9186 image
= image_spec_value (img
->spec
, QCindex
, NULL
);
9187 ino
= INTEGERP (image
) ? XFASTINT (image
) : 0;
9188 if (ino
>= gif
->ImageCount
)
9190 image_error ("Invalid image number `%s' in image `%s'",
9192 DGifCloseFile (gif
);
9197 width
= img
->width
= max (gif
->SWidth
, gif
->Image
.Left
+ gif
->Image
.Width
);
9198 height
= img
->height
= max (gif
->SHeight
, gif
->Image
.Top
+ gif
->Image
.Height
);
9200 /* Create the X image and pixmap. */
9201 if (!x_create_x_image_and_pixmap (f
, width
, height
, 0, &ximg
, &img
->pixmap
))
9203 DGifCloseFile (gif
);
9208 /* Allocate colors. */
9209 gif_color_map
= gif
->SavedImages
[ino
].ImageDesc
.ColorMap
;
9211 gif_color_map
= gif
->SColorMap
;
9212 init_color_table ();
9213 bzero (pixel_colors
, sizeof pixel_colors
);
9215 for (i
= 0; i
< gif_color_map
->ColorCount
; ++i
)
9217 int r
= gif_color_map
->Colors
[i
].Red
<< 8;
9218 int g
= gif_color_map
->Colors
[i
].Green
<< 8;
9219 int b
= gif_color_map
->Colors
[i
].Blue
<< 8;
9220 pixel_colors
[i
] = lookup_rgb_color (f
, r
, g
, b
);
9223 img
->colors
= colors_in_color_table (&img
->ncolors
);
9224 free_color_table ();
9226 /* Clear the part of the screen image that are not covered by
9227 the image from the GIF file. Full animated GIF support
9228 requires more than can be done here (see the gif89 spec,
9229 disposal methods). Let's simply assume that the part
9230 not covered by a sub-image is in the frame's background color. */
9231 image_top
= gif
->SavedImages
[ino
].ImageDesc
.Top
;
9232 image_left
= gif
->SavedImages
[ino
].ImageDesc
.Left
;
9233 image_width
= gif
->SavedImages
[ino
].ImageDesc
.Width
;
9234 image_height
= gif
->SavedImages
[ino
].ImageDesc
.Height
;
9236 for (y
= 0; y
< image_top
; ++y
)
9237 for (x
= 0; x
< width
; ++x
)
9238 XPutPixel (ximg
, x
, y
, FRAME_BACKGROUND_PIXEL (f
));
9240 for (y
= image_top
+ image_height
; y
< height
; ++y
)
9241 for (x
= 0; x
< width
; ++x
)
9242 XPutPixel (ximg
, x
, y
, FRAME_BACKGROUND_PIXEL (f
));
9244 for (y
= image_top
; y
< image_top
+ image_height
; ++y
)
9246 for (x
= 0; x
< image_left
; ++x
)
9247 XPutPixel (ximg
, x
, y
, FRAME_BACKGROUND_PIXEL (f
));
9248 for (x
= image_left
+ image_width
; x
< width
; ++x
)
9249 XPutPixel (ximg
, x
, y
, FRAME_BACKGROUND_PIXEL (f
));
9252 /* Read the GIF image into the X image. We use a local variable
9253 `raster' here because RasterBits below is a char *, and invites
9254 problems with bytes >= 0x80. */
9255 raster
= (unsigned char *) gif
->SavedImages
[ino
].RasterBits
;
9257 if (gif
->SavedImages
[ino
].ImageDesc
.Interlace
)
9259 static int interlace_start
[] = {0, 4, 2, 1};
9260 static int interlace_increment
[] = {8, 8, 4, 2};
9262 int row
= interlace_start
[0];
9266 for (y
= 0; y
< image_height
; y
++)
9268 if (row
>= image_height
)
9270 row
= interlace_start
[++pass
];
9271 while (row
>= image_height
)
9272 row
= interlace_start
[++pass
];
9275 for (x
= 0; x
< image_width
; x
++)
9277 int i
= raster
[(y
* image_width
) + x
];
9278 XPutPixel (ximg
, x
+ image_left
, row
+ image_top
,
9282 row
+= interlace_increment
[pass
];
9287 for (y
= 0; y
< image_height
; ++y
)
9288 for (x
= 0; x
< image_width
; ++x
)
9290 int i
= raster
[y
* image_width
+ x
];
9291 XPutPixel (ximg
, x
+ image_left
, y
+ image_top
, pixel_colors
[i
]);
9295 DGifCloseFile (gif
);
9297 /* Maybe fill in the background field while we have ximg handy. */
9298 if (NILP (image_spec_value (img
->spec
, QCbackground
, NULL
)))
9299 IMAGE_BACKGROUND (img
, f
, ximg
);
9301 /* Put the image into the pixmap, then free the X image and its buffer. */
9302 x_put_x_image (f
, ximg
, img
->pixmap
, width
, height
);
9303 x_destroy_x_image (ximg
);
9309 #endif /* HAVE_GIF != 0 */
9313 /***********************************************************************
9315 ***********************************************************************/
9317 static int gs_image_p
P_ ((Lisp_Object object
));
9318 static int gs_load
P_ ((struct frame
*f
, struct image
*img
));
9319 static void gs_clear_image
P_ ((struct frame
*f
, struct image
*img
));
9321 /* The symbol `postscript' identifying images of this type. */
9323 Lisp_Object Qpostscript
;
9325 /* Keyword symbols. */
9327 Lisp_Object QCloader
, QCbounding_box
, QCpt_width
, QCpt_height
;
9329 /* Indices of image specification fields in gs_format, below. */
9331 enum gs_keyword_index
9349 /* Vector of image_keyword structures describing the format
9350 of valid user-defined image specifications. */
9352 static struct image_keyword gs_format
[GS_LAST
] =
9354 {":type", IMAGE_SYMBOL_VALUE
, 1},
9355 {":pt-width", IMAGE_POSITIVE_INTEGER_VALUE
, 1},
9356 {":pt-height", IMAGE_POSITIVE_INTEGER_VALUE
, 1},
9357 {":file", IMAGE_STRING_VALUE
, 1},
9358 {":loader", IMAGE_FUNCTION_VALUE
, 0},
9359 {":bounding-box", IMAGE_DONT_CHECK_VALUE_TYPE
, 1},
9360 {":ascent", IMAGE_ASCENT_VALUE
, 0},
9361 {":margin", IMAGE_POSITIVE_INTEGER_VALUE_OR_PAIR
, 0},
9362 {":relief", IMAGE_INTEGER_VALUE
, 0},
9363 {":conversion", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
9364 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
9365 {":mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
9366 {":background", IMAGE_STRING_OR_NIL_VALUE
, 0}
9369 /* Structure describing the image type `ghostscript'. */
9371 static struct image_type gs_type
=
9381 /* Free X resources of Ghostscript image IMG which is used on frame F. */
9384 gs_clear_image (f
, img
)
9388 /* IMG->data.ptr_val may contain a recorded colormap. */
9389 xfree (img
->data
.ptr_val
);
9390 x_clear_image (f
, img
);
9394 /* Return non-zero if OBJECT is a valid Ghostscript image
9401 struct image_keyword fmt
[GS_LAST
];
9405 bcopy (gs_format
, fmt
, sizeof fmt
);
9407 if (!parse_image_spec (object
, fmt
, GS_LAST
, Qpostscript
))
9410 /* Bounding box must be a list or vector containing 4 integers. */
9411 tem
= fmt
[GS_BOUNDING_BOX
].value
;
9414 for (i
= 0; i
< 4; ++i
, tem
= XCDR (tem
))
9415 if (!CONSP (tem
) || !INTEGERP (XCAR (tem
)))
9420 else if (VECTORP (tem
))
9422 if (XVECTOR (tem
)->size
!= 4)
9424 for (i
= 0; i
< 4; ++i
)
9425 if (!INTEGERP (XVECTOR (tem
)->contents
[i
]))
9435 /* Load Ghostscript image IMG for use on frame F. Value is non-zero
9444 Lisp_Object window_and_pixmap_id
= Qnil
, loader
, pt_height
, pt_width
;
9445 struct gcpro gcpro1
, gcpro2
;
9447 double in_width
, in_height
;
9448 Lisp_Object pixel_colors
= Qnil
;
9450 /* Compute pixel size of pixmap needed from the given size in the
9451 image specification. Sizes in the specification are in pt. 1 pt
9452 = 1/72 in, xdpi and ydpi are stored in the frame's X display
9454 pt_width
= image_spec_value (img
->spec
, QCpt_width
, NULL
);
9455 in_width
= XFASTINT (pt_width
) / 72.0;
9456 img
->width
= in_width
* FRAME_X_DISPLAY_INFO (f
)->resx
;
9457 pt_height
= image_spec_value (img
->spec
, QCpt_height
, NULL
);
9458 in_height
= XFASTINT (pt_height
) / 72.0;
9459 img
->height
= in_height
* FRAME_X_DISPLAY_INFO (f
)->resy
;
9461 /* Create the pixmap. */
9462 xassert (img
->pixmap
== None
);
9463 img
->pixmap
= XCreatePixmap (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
9464 img
->width
, img
->height
,
9465 DefaultDepthOfScreen (FRAME_X_SCREEN (f
)));
9469 image_error ("Unable to create pixmap for `%s'", img
->spec
, Qnil
);
9473 /* Call the loader to fill the pixmap. It returns a process object
9474 if successful. We do not record_unwind_protect here because
9475 other places in redisplay like calling window scroll functions
9476 don't either. Let the Lisp loader use `unwind-protect' instead. */
9477 GCPRO2 (window_and_pixmap_id
, pixel_colors
);
9479 sprintf (buffer
, "%lu %lu",
9480 (unsigned long) FRAME_X_WINDOW (f
),
9481 (unsigned long) img
->pixmap
);
9482 window_and_pixmap_id
= build_string (buffer
);
9484 sprintf (buffer
, "%lu %lu",
9485 FRAME_FOREGROUND_PIXEL (f
),
9486 FRAME_BACKGROUND_PIXEL (f
));
9487 pixel_colors
= build_string (buffer
);
9489 XSETFRAME (frame
, f
);
9490 loader
= image_spec_value (img
->spec
, QCloader
, NULL
);
9492 loader
= intern ("gs-load-image");
9494 img
->data
.lisp_val
= call6 (loader
, frame
, img
->spec
,
9495 make_number (img
->width
),
9496 make_number (img
->height
),
9497 window_and_pixmap_id
,
9500 return PROCESSP (img
->data
.lisp_val
);
9504 /* Kill the Ghostscript process that was started to fill PIXMAP on
9505 frame F. Called from XTread_socket when receiving an event
9506 telling Emacs that Ghostscript has finished drawing. */
9509 x_kill_gs_process (pixmap
, f
)
9513 struct image_cache
*c
= FRAME_X_IMAGE_CACHE (f
);
9517 /* Find the image containing PIXMAP. */
9518 for (i
= 0; i
< c
->used
; ++i
)
9519 if (c
->images
[i
]->pixmap
== pixmap
)
9522 /* Should someone in between have cleared the image cache, for
9523 instance, give up. */
9527 /* Kill the GS process. We should have found PIXMAP in the image
9528 cache and its image should contain a process object. */
9530 xassert (PROCESSP (img
->data
.lisp_val
));
9531 Fkill_process (img
->data
.lisp_val
, Qnil
);
9532 img
->data
.lisp_val
= Qnil
;
9534 /* On displays with a mutable colormap, figure out the colors
9535 allocated for the image by looking at the pixels of an XImage for
9537 class = FRAME_X_VISUAL (f
)->class;
9538 if (class != StaticColor
&& class != StaticGray
&& class != TrueColor
)
9544 /* Try to get an XImage for img->pixmep. */
9545 ximg
= XGetImage (FRAME_X_DISPLAY (f
), img
->pixmap
,
9546 0, 0, img
->width
, img
->height
, ~0, ZPixmap
);
9551 /* Initialize the color table. */
9552 init_color_table ();
9554 /* For each pixel of the image, look its color up in the
9555 color table. After having done so, the color table will
9556 contain an entry for each color used by the image. */
9557 for (y
= 0; y
< img
->height
; ++y
)
9558 for (x
= 0; x
< img
->width
; ++x
)
9560 unsigned long pixel
= XGetPixel (ximg
, x
, y
);
9561 lookup_pixel_color (f
, pixel
);
9564 /* Record colors in the image. Free color table and XImage. */
9565 img
->colors
= colors_in_color_table (&img
->ncolors
);
9566 free_color_table ();
9567 XDestroyImage (ximg
);
9569 #if 0 /* This doesn't seem to be the case. If we free the colors
9570 here, we get a BadAccess later in x_clear_image when
9571 freeing the colors. */
9572 /* We have allocated colors once, but Ghostscript has also
9573 allocated colors on behalf of us. So, to get the
9574 reference counts right, free them once. */
9576 x_free_colors (f
, img
->colors
, img
->ncolors
);
9580 image_error ("Cannot get X image of `%s'; colors will not be freed",
9586 /* Now that we have the pixmap, compute mask and transform the
9587 image if requested. */
9589 postprocess_image (f
, img
);
9595 /***********************************************************************
9597 ***********************************************************************/
9599 DEFUN ("x-change-window-property", Fx_change_window_property
,
9600 Sx_change_window_property
, 2, 3, 0,
9601 doc
: /* Change window property PROP to VALUE on the X window of FRAME.
9602 PROP and VALUE must be strings. FRAME nil or omitted means use the
9603 selected frame. Value is VALUE. */)
9604 (prop
, value
, frame
)
9605 Lisp_Object frame
, prop
, value
;
9607 struct frame
*f
= check_x_frame (frame
);
9610 CHECK_STRING (prop
);
9611 CHECK_STRING (value
);
9614 prop_atom
= XInternAtom (FRAME_X_DISPLAY (f
), SDATA (prop
), False
);
9615 XChangeProperty (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
9616 prop_atom
, XA_STRING
, 8, PropModeReplace
,
9617 SDATA (value
), SCHARS (value
));
9619 /* Make sure the property is set when we return. */
9620 XFlush (FRAME_X_DISPLAY (f
));
9627 DEFUN ("x-delete-window-property", Fx_delete_window_property
,
9628 Sx_delete_window_property
, 1, 2, 0,
9629 doc
: /* Remove window property PROP from X window of FRAME.
9630 FRAME nil or omitted means use the selected frame. Value is PROP. */)
9632 Lisp_Object prop
, frame
;
9634 struct frame
*f
= check_x_frame (frame
);
9637 CHECK_STRING (prop
);
9639 prop_atom
= XInternAtom (FRAME_X_DISPLAY (f
), SDATA (prop
), False
);
9640 XDeleteProperty (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), prop_atom
);
9642 /* Make sure the property is removed when we return. */
9643 XFlush (FRAME_X_DISPLAY (f
));
9650 DEFUN ("x-window-property", Fx_window_property
, Sx_window_property
,
9652 doc
: /* Value is the value of window property PROP on FRAME.
9653 If FRAME is nil or omitted, use the selected frame. Value is nil
9654 if FRAME hasn't a property with name PROP or if PROP has no string
9657 Lisp_Object prop
, frame
;
9659 struct frame
*f
= check_x_frame (frame
);
9662 Lisp_Object prop_value
= Qnil
;
9663 char *tmp_data
= NULL
;
9666 unsigned long actual_size
, bytes_remaining
;
9668 CHECK_STRING (prop
);
9670 prop_atom
= XInternAtom (FRAME_X_DISPLAY (f
), SDATA (prop
), False
);
9671 rc
= XGetWindowProperty (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
9672 prop_atom
, 0, 0, False
, XA_STRING
,
9673 &actual_type
, &actual_format
, &actual_size
,
9674 &bytes_remaining
, (unsigned char **) &tmp_data
);
9677 int size
= bytes_remaining
;
9682 rc
= XGetWindowProperty (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
9683 prop_atom
, 0, bytes_remaining
,
9685 &actual_type
, &actual_format
,
9686 &actual_size
, &bytes_remaining
,
9687 (unsigned char **) &tmp_data
);
9688 if (rc
== Success
&& tmp_data
)
9689 prop_value
= make_string (tmp_data
, size
);
9700 /***********************************************************************
9702 ***********************************************************************/
9704 /* If non-null, an asynchronous timer that, when it expires, displays
9705 an hourglass cursor on all frames. */
9707 static struct atimer
*hourglass_atimer
;
9709 /* Non-zero means an hourglass cursor is currently shown. */
9711 static int hourglass_shown_p
;
9713 /* Number of seconds to wait before displaying an hourglass cursor. */
9715 static Lisp_Object Vhourglass_delay
;
9717 /* Default number of seconds to wait before displaying an hourglass
9720 #define DEFAULT_HOURGLASS_DELAY 1
9722 /* Function prototypes. */
9724 static void show_hourglass
P_ ((struct atimer
*));
9725 static void hide_hourglass
P_ ((void));
9728 /* Cancel a currently active hourglass timer, and start a new one. */
9734 int secs
, usecs
= 0;
9736 cancel_hourglass ();
9738 if (INTEGERP (Vhourglass_delay
)
9739 && XINT (Vhourglass_delay
) > 0)
9740 secs
= XFASTINT (Vhourglass_delay
);
9741 else if (FLOATP (Vhourglass_delay
)
9742 && XFLOAT_DATA (Vhourglass_delay
) > 0)
9745 tem
= Ftruncate (Vhourglass_delay
, Qnil
);
9746 secs
= XFASTINT (tem
);
9747 usecs
= (XFLOAT_DATA (Vhourglass_delay
) - secs
) * 1000000;
9750 secs
= DEFAULT_HOURGLASS_DELAY
;
9752 EMACS_SET_SECS_USECS (delay
, secs
, usecs
);
9753 hourglass_atimer
= start_atimer (ATIMER_RELATIVE
, delay
,
9754 show_hourglass
, NULL
);
9758 /* Cancel the hourglass cursor timer if active, hide a busy cursor if
9764 if (hourglass_atimer
)
9766 cancel_atimer (hourglass_atimer
);
9767 hourglass_atimer
= NULL
;
9770 if (hourglass_shown_p
)
9775 /* Timer function of hourglass_atimer. TIMER is equal to
9778 Display an hourglass pointer on all frames by mapping the frames'
9779 hourglass_window. Set the hourglass_p flag in the frames'
9780 output_data.x structure to indicate that an hourglass cursor is
9781 shown on the frames. */
9784 show_hourglass (timer
)
9785 struct atimer
*timer
;
9787 /* The timer implementation will cancel this timer automatically
9788 after this function has run. Set hourglass_atimer to null
9789 so that we know the timer doesn't have to be canceled. */
9790 hourglass_atimer
= NULL
;
9792 if (!hourglass_shown_p
)
9794 Lisp_Object rest
, frame
;
9798 FOR_EACH_FRAME (rest
, frame
)
9800 struct frame
*f
= XFRAME (frame
);
9802 if (FRAME_LIVE_P (f
) && FRAME_X_P (f
) && FRAME_X_DISPLAY (f
))
9804 Display
*dpy
= FRAME_X_DISPLAY (f
);
9806 #ifdef USE_X_TOOLKIT
9807 if (f
->output_data
.x
->widget
)
9809 if (FRAME_OUTER_WINDOW (f
))
9812 f
->output_data
.x
->hourglass_p
= 1;
9814 if (!f
->output_data
.x
->hourglass_window
)
9816 unsigned long mask
= CWCursor
;
9817 XSetWindowAttributes attrs
;
9819 attrs
.cursor
= f
->output_data
.x
->hourglass_cursor
;
9821 f
->output_data
.x
->hourglass_window
9822 = XCreateWindow (dpy
, FRAME_OUTER_WINDOW (f
),
9823 0, 0, 32000, 32000, 0, 0,
9829 XMapRaised (dpy
, f
->output_data
.x
->hourglass_window
);
9835 hourglass_shown_p
= 1;
9841 /* Hide the hourglass pointer on all frames, if it is currently
9847 if (hourglass_shown_p
)
9849 Lisp_Object rest
, frame
;
9852 FOR_EACH_FRAME (rest
, frame
)
9854 struct frame
*f
= XFRAME (frame
);
9857 /* Watch out for newly created frames. */
9858 && f
->output_data
.x
->hourglass_window
)
9860 XUnmapWindow (FRAME_X_DISPLAY (f
),
9861 f
->output_data
.x
->hourglass_window
);
9862 /* Sync here because XTread_socket looks at the
9863 hourglass_p flag that is reset to zero below. */
9864 XSync (FRAME_X_DISPLAY (f
), False
);
9865 f
->output_data
.x
->hourglass_p
= 0;
9869 hourglass_shown_p
= 0;
9876 /***********************************************************************
9878 ***********************************************************************/
9880 static Lisp_Object x_create_tip_frame
P_ ((struct x_display_info
*,
9881 Lisp_Object
, Lisp_Object
));
9882 static void compute_tip_xy
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
,
9883 Lisp_Object
, int, int, int *, int *));
9885 /* The frame of a currently visible tooltip. */
9887 Lisp_Object tip_frame
;
9889 /* If non-nil, a timer started that hides the last tooltip when it
9892 Lisp_Object tip_timer
;
9895 /* If non-nil, a vector of 3 elements containing the last args
9896 with which x-show-tip was called. See there. */
9898 Lisp_Object last_show_tip_args
;
9900 /* Maximum size for tooltips; a cons (COLUMNS . ROWS). */
9902 Lisp_Object Vx_max_tooltip_size
;
9906 unwind_create_tip_frame (frame
)
9909 Lisp_Object deleted
;
9911 deleted
= unwind_create_frame (frame
);
9912 if (EQ (deleted
, Qt
))
9922 /* Create a frame for a tooltip on the display described by DPYINFO.
9923 PARMS is a list of frame parameters. TEXT is the string to
9924 display in the tip frame. Value is the frame.
9926 Note that functions called here, esp. x_default_parameter can
9927 signal errors, for instance when a specified color name is
9928 undefined. We have to make sure that we're in a consistent state
9929 when this happens. */
9932 x_create_tip_frame (dpyinfo
, parms
, text
)
9933 struct x_display_info
*dpyinfo
;
9934 Lisp_Object parms
, text
;
9937 Lisp_Object frame
, tem
;
9939 long window_prompting
= 0;
9941 int count
= SPECPDL_INDEX ();
9942 struct gcpro gcpro1
, gcpro2
, gcpro3
;
9944 int face_change_count_before
= face_change_count
;
9946 struct buffer
*old_buffer
;
9950 /* Use this general default value to start with until we know if
9951 this frame has a specified name. */
9952 Vx_resource_name
= Vinvocation_name
;
9955 kb
= dpyinfo
->kboard
;
9957 kb
= &the_only_kboard
;
9960 /* Get the name of the frame to use for resource lookup. */
9961 name
= x_get_arg (dpyinfo
, parms
, Qname
, "name", "Name", RES_TYPE_STRING
);
9963 && !EQ (name
, Qunbound
)
9965 error ("Invalid frame name--not a string or nil");
9966 Vx_resource_name
= name
;
9969 GCPRO3 (parms
, name
, frame
);
9971 XSETFRAME (frame
, f
);
9973 buffer
= Fget_buffer_create (build_string (" *tip*"));
9974 Fset_window_buffer (FRAME_ROOT_WINDOW (f
), buffer
, Qnil
);
9975 old_buffer
= current_buffer
;
9976 set_buffer_internal_1 (XBUFFER (buffer
));
9977 current_buffer
->truncate_lines
= Qnil
;
9980 set_buffer_internal_1 (old_buffer
);
9982 FRAME_CAN_HAVE_SCROLL_BARS (f
) = 0;
9983 record_unwind_protect (unwind_create_tip_frame
, frame
);
9985 f
->display
= dpyinfo
->frame_display
;
9986 f
->display
->reference_count
++;
9988 /* By setting the output method, we're essentially saying that
9989 the frame is live, as per FRAME_LIVE_P. If we get a signal
9990 from this point on, x_destroy_window might screw up reference
9992 f
->output_method
= output_x_window
;
9993 f
->output_data
.x
= (struct x_output
*) xmalloc (sizeof (struct x_output
));
9994 bzero (f
->output_data
.x
, sizeof (struct x_output
));
9995 f
->output_data
.x
->icon_bitmap
= -1;
9996 FRAME_FONTSET (f
) = -1;
9997 f
->output_data
.x
->scroll_bar_foreground_pixel
= -1;
9998 f
->output_data
.x
->scroll_bar_background_pixel
= -1;
9999 #ifdef USE_TOOLKIT_SCROLL_BARS
10000 f
->output_data
.x
->scroll_bar_top_shadow_pixel
= -1;
10001 f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
= -1;
10002 #endif /* USE_TOOLKIT_SCROLL_BARS */
10003 f
->icon_name
= Qnil
;
10004 FRAME_X_DISPLAY_INFO (f
) = dpyinfo
;
10006 image_cache_refcount
= FRAME_X_IMAGE_CACHE (f
)->refcount
;
10007 dpyinfo_refcount
= dpyinfo
->reference_count
;
10008 #endif /* GLYPH_DEBUG */
10009 #ifdef MULTI_KBOARD
10010 FRAME_KBOARD (f
) = kb
;
10012 f
->output_data
.x
->parent_desc
= FRAME_X_DISPLAY_INFO (f
)->root_window
;
10013 f
->output_data
.x
->explicit_parent
= 0;
10015 /* These colors will be set anyway later, but it's important
10016 to get the color reference counts right, so initialize them! */
10019 struct gcpro gcpro1
;
10021 black
= build_string ("black");
10023 f
->output_data
.x
->foreground_pixel
10024 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
10025 f
->output_data
.x
->background_pixel
10026 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
10027 f
->output_data
.x
->cursor_pixel
10028 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
10029 f
->output_data
.x
->cursor_foreground_pixel
10030 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
10031 f
->output_data
.x
->border_pixel
10032 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
10033 f
->output_data
.x
->mouse_pixel
10034 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
10038 /* Set the name; the functions to which we pass f expect the name to
10040 if (EQ (name
, Qunbound
) || NILP (name
))
10042 f
->name
= build_string (dpyinfo
->x_id_name
);
10043 f
->explicit_name
= 0;
10048 f
->explicit_name
= 1;
10049 /* use the frame's title when getting resources for this frame. */
10050 specbind (Qx_resource_name
, name
);
10053 /* Extract the window parameters from the supplied values that are
10054 needed to determine window geometry. */
10058 font
= x_get_arg (dpyinfo
, parms
, Qfont
, "font", "Font", RES_TYPE_STRING
);
10061 /* First, try whatever font the caller has specified. */
10062 if (STRINGP (font
))
10064 tem
= Fquery_fontset (font
, Qnil
);
10066 font
= x_new_fontset (f
, SDATA (tem
));
10068 font
= x_new_font (f
, SDATA (font
));
10071 /* Try out a font which we hope has bold and italic variations. */
10072 if (!STRINGP (font
))
10073 font
= x_new_font (f
, "-adobe-courier-medium-r-*-*-*-120-*-*-*-*-iso8859-1");
10074 if (!STRINGP (font
))
10075 font
= x_new_font (f
, "-misc-fixed-medium-r-normal-*-*-140-*-*-c-*-iso8859-1");
10076 if (! STRINGP (font
))
10077 font
= x_new_font (f
, "-*-*-medium-r-normal-*-*-140-*-*-c-*-iso8859-1");
10078 if (! STRINGP (font
))
10079 /* This was formerly the first thing tried, but it finds too many fonts
10080 and takes too long. */
10081 font
= x_new_font (f
, "-*-*-medium-r-*-*-*-*-*-*-c-*-iso8859-1");
10082 /* If those didn't work, look for something which will at least work. */
10083 if (! STRINGP (font
))
10084 font
= x_new_font (f
, "-*-fixed-*-*-*-*-*-140-*-*-c-*-iso8859-1");
10086 if (! STRINGP (font
))
10087 font
= build_string ("fixed");
10089 x_default_parameter (f
, parms
, Qfont
, font
,
10090 "font", "Font", RES_TYPE_STRING
);
10093 x_default_parameter (f
, parms
, Qborder_width
, make_number (2),
10094 "borderWidth", "BorderWidth", RES_TYPE_NUMBER
);
10096 /* This defaults to 2 in order to match xterm. We recognize either
10097 internalBorderWidth or internalBorder (which is what xterm calls
10099 if (NILP (Fassq (Qinternal_border_width
, parms
)))
10103 value
= x_get_arg (dpyinfo
, parms
, Qinternal_border_width
,
10104 "internalBorder", "internalBorder", RES_TYPE_NUMBER
);
10105 if (! EQ (value
, Qunbound
))
10106 parms
= Fcons (Fcons (Qinternal_border_width
, value
),
10110 x_default_parameter (f
, parms
, Qinternal_border_width
, make_number (1),
10111 "internalBorderWidth", "internalBorderWidth",
10114 /* Also do the stuff which must be set before the window exists. */
10115 x_default_parameter (f
, parms
, Qforeground_color
, build_string ("black"),
10116 "foreground", "Foreground", RES_TYPE_STRING
);
10117 x_default_parameter (f
, parms
, Qbackground_color
, build_string ("white"),
10118 "background", "Background", RES_TYPE_STRING
);
10119 x_default_parameter (f
, parms
, Qmouse_color
, build_string ("black"),
10120 "pointerColor", "Foreground", RES_TYPE_STRING
);
10121 x_default_parameter (f
, parms
, Qcursor_color
, build_string ("black"),
10122 "cursorColor", "Foreground", RES_TYPE_STRING
);
10123 x_default_parameter (f
, parms
, Qborder_color
, build_string ("black"),
10124 "borderColor", "BorderColor", RES_TYPE_STRING
);
10126 /* Init faces before x_default_parameter is called for scroll-bar
10127 parameters because that function calls x_set_scroll_bar_width,
10128 which calls change_frame_size, which calls Fset_window_buffer,
10129 which runs hooks, which call Fvertical_motion. At the end, we
10130 end up in init_iterator with a null face cache, which should not
10132 init_frame_faces (f
);
10134 f
->output_data
.x
->parent_desc
= FRAME_X_DISPLAY_INFO (f
)->root_window
;
10136 window_prompting
= x_figure_window_size (f
, parms
, 0);
10139 XSetWindowAttributes attrs
;
10140 unsigned long mask
;
10143 mask
= CWBackPixel
| CWOverrideRedirect
| CWEventMask
;
10144 if (DoesSaveUnders (dpyinfo
->screen
))
10145 mask
|= CWSaveUnder
;
10147 /* Window managers look at the override-redirect flag to determine
10148 whether or net to give windows a decoration (Xlib spec, chapter
10150 attrs
.override_redirect
= True
;
10151 attrs
.save_under
= True
;
10152 attrs
.background_pixel
= FRAME_BACKGROUND_PIXEL (f
);
10153 /* Arrange for getting MapNotify and UnmapNotify events. */
10154 attrs
.event_mask
= StructureNotifyMask
;
10156 = FRAME_X_WINDOW (f
)
10157 = XCreateWindow (FRAME_X_DISPLAY (f
),
10158 FRAME_X_DISPLAY_INFO (f
)->root_window
,
10159 /* x, y, width, height */
10163 CopyFromParent
, InputOutput
, CopyFromParent
,
10170 x_default_parameter (f
, parms
, Qauto_raise
, Qnil
,
10171 "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
10172 x_default_parameter (f
, parms
, Qauto_lower
, Qnil
,
10173 "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
10174 x_default_parameter (f
, parms
, Qcursor_type
, Qbox
,
10175 "cursorType", "CursorType", RES_TYPE_SYMBOL
);
10177 /* Dimensions, especially FRAME_LINES (f), must be done via change_frame_size.
10178 Change will not be effected unless different from the current
10179 FRAME_LINES (f). */
10180 width
= FRAME_COLS (f
);
10181 height
= FRAME_LINES (f
);
10182 SET_FRAME_COLS (f
, 0);
10183 FRAME_LINES (f
) = 0;
10184 change_frame_size (f
, height
, width
, 1, 0, 0);
10186 /* Add `tooltip' frame parameter's default value. */
10187 if (NILP (Fframe_parameter (frame
, intern ("tooltip"))))
10188 Fmodify_frame_parameters (frame
, Fcons (Fcons (intern ("tooltip"), Qt
),
10191 /* Set up faces after all frame parameters are known. This call
10192 also merges in face attributes specified for new frames.
10194 Frame parameters may be changed if .Xdefaults contains
10195 specifications for the default font. For example, if there is an
10196 `Emacs.default.attributeBackground: pink', the `background-color'
10197 attribute of the frame get's set, which let's the internal border
10198 of the tooltip frame appear in pink. Prevent this. */
10200 Lisp_Object bg
= Fframe_parameter (frame
, Qbackground_color
);
10202 /* Set tip_frame here, so that */
10204 call1 (Qface_set_after_frame_default
, frame
);
10206 if (!EQ (bg
, Fframe_parameter (frame
, Qbackground_color
)))
10207 Fmodify_frame_parameters (frame
, Fcons (Fcons (Qbackground_color
, bg
),
10215 /* It is now ok to make the frame official even if we get an error
10216 below. And the frame needs to be on Vframe_list or making it
10217 visible won't work. */
10218 Vframe_list
= Fcons (frame
, Vframe_list
);
10220 /* Now that the frame is official, it counts as a reference to
10222 FRAME_X_DISPLAY_INFO (f
)->reference_count
++;
10224 /* Setting attributes of faces of the tooltip frame from resources
10225 and similar will increment face_change_count, which leads to the
10226 clearing of all current matrices. Since this isn't necessary
10227 here, avoid it by resetting face_change_count to the value it
10228 had before we created the tip frame. */
10229 face_change_count
= face_change_count_before
;
10231 /* Discard the unwind_protect. */
10232 return unbind_to (count
, frame
);
10236 /* Compute where to display tip frame F. PARMS is the list of frame
10237 parameters for F. DX and DY are specified offsets from the current
10238 location of the mouse. WIDTH and HEIGHT are the width and height
10239 of the tooltip. Return coordinates relative to the root window of
10240 the display in *ROOT_X, and *ROOT_Y. */
10243 compute_tip_xy (f
, parms
, dx
, dy
, width
, height
, root_x
, root_y
)
10245 Lisp_Object parms
, dx
, dy
;
10247 int *root_x
, *root_y
;
10249 Lisp_Object left
, top
;
10251 Window root
, child
;
10254 /* User-specified position? */
10255 left
= Fcdr (Fassq (Qleft
, parms
));
10256 top
= Fcdr (Fassq (Qtop
, parms
));
10258 /* Move the tooltip window where the mouse pointer is. Resize and
10260 if (!INTEGERP (left
) || !INTEGERP (top
))
10263 XQueryPointer (FRAME_X_DISPLAY (f
), FRAME_X_DISPLAY_INFO (f
)->root_window
,
10264 &root
, &child
, root_x
, root_y
, &win_x
, &win_y
, &pmask
);
10268 if (INTEGERP (top
))
10269 *root_y
= XINT (top
);
10270 else if (*root_y
+ XINT (dy
) - height
< 0)
10271 *root_y
-= XINT (dy
);
10275 *root_y
+= XINT (dy
);
10278 if (INTEGERP (left
))
10279 *root_x
= XINT (left
);
10280 else if (*root_x
+ XINT (dx
) + width
<= FRAME_X_DISPLAY_INFO (f
)->width
)
10281 /* It fits to the right of the pointer. */
10282 *root_x
+= XINT (dx
);
10283 else if (width
+ XINT (dx
) <= *root_x
)
10284 /* It fits to the left of the pointer. */
10285 *root_x
-= width
+ XINT (dx
);
10287 /* Put it left-justified on the screen--it ought to fit that way. */
10292 DEFUN ("x-show-tip", Fx_show_tip
, Sx_show_tip
, 1, 6, 0,
10293 doc
: /* Show STRING in a "tooltip" window on frame FRAME.
10294 A tooltip window is a small X window displaying a string.
10296 FRAME nil or omitted means use the selected frame.
10298 PARMS is an optional list of frame parameters which can be used to
10299 change the tooltip's appearance.
10301 Automatically hide the tooltip after TIMEOUT seconds. TIMEOUT nil
10302 means use the default timeout of 5 seconds.
10304 If the list of frame parameters PARAMS contains a `left' parameters,
10305 the tooltip is displayed at that x-position. Otherwise it is
10306 displayed at the mouse position, with offset DX added (default is 5 if
10307 DX isn't specified). Likewise for the y-position; if a `top' frame
10308 parameter is specified, it determines the y-position of the tooltip
10309 window, otherwise it is displayed at the mouse position, with offset
10310 DY added (default is -10).
10312 A tooltip's maximum size is specified by `x-max-tooltip-size'.
10313 Text larger than the specified size is clipped. */)
10314 (string
, frame
, parms
, timeout
, dx
, dy
)
10315 Lisp_Object string
, frame
, parms
, timeout
, dx
, dy
;
10319 int root_x
, root_y
;
10320 struct buffer
*old_buffer
;
10321 struct text_pos pos
;
10322 int i
, width
, height
;
10323 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
10324 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
10325 int count
= SPECPDL_INDEX ();
10327 specbind (Qinhibit_redisplay
, Qt
);
10329 GCPRO4 (string
, parms
, frame
, timeout
);
10331 CHECK_STRING (string
);
10332 f
= check_x_frame (frame
);
10333 if (NILP (timeout
))
10334 timeout
= make_number (5);
10336 CHECK_NATNUM (timeout
);
10339 dx
= make_number (5);
10344 dy
= make_number (-10);
10348 if (NILP (last_show_tip_args
))
10349 last_show_tip_args
= Fmake_vector (make_number (3), Qnil
);
10351 if (!NILP (tip_frame
))
10353 Lisp_Object last_string
= AREF (last_show_tip_args
, 0);
10354 Lisp_Object last_frame
= AREF (last_show_tip_args
, 1);
10355 Lisp_Object last_parms
= AREF (last_show_tip_args
, 2);
10357 if (EQ (frame
, last_frame
)
10358 && !NILP (Fequal (last_string
, string
))
10359 && !NILP (Fequal (last_parms
, parms
)))
10361 struct frame
*f
= XFRAME (tip_frame
);
10363 /* Only DX and DY have changed. */
10364 if (!NILP (tip_timer
))
10366 Lisp_Object timer
= tip_timer
;
10368 call1 (Qcancel_timer
, timer
);
10372 compute_tip_xy (f
, parms
, dx
, dy
, FRAME_PIXEL_WIDTH (f
),
10373 FRAME_PIXEL_HEIGHT (f
), &root_x
, &root_y
);
10374 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
10381 /* Hide a previous tip, if any. */
10384 ASET (last_show_tip_args
, 0, string
);
10385 ASET (last_show_tip_args
, 1, frame
);
10386 ASET (last_show_tip_args
, 2, parms
);
10388 /* Add default values to frame parameters. */
10389 if (NILP (Fassq (Qname
, parms
)))
10390 parms
= Fcons (Fcons (Qname
, build_string ("tooltip")), parms
);
10391 if (NILP (Fassq (Qinternal_border_width
, parms
)))
10392 parms
= Fcons (Fcons (Qinternal_border_width
, make_number (3)), parms
);
10393 if (NILP (Fassq (Qborder_width
, parms
)))
10394 parms
= Fcons (Fcons (Qborder_width
, make_number (1)), parms
);
10395 if (NILP (Fassq (Qborder_color
, parms
)))
10396 parms
= Fcons (Fcons (Qborder_color
, build_string ("lightyellow")), parms
);
10397 if (NILP (Fassq (Qbackground_color
, parms
)))
10398 parms
= Fcons (Fcons (Qbackground_color
, build_string ("lightyellow")),
10401 /* Create a frame for the tooltip, and record it in the global
10402 variable tip_frame. */
10403 frame
= x_create_tip_frame (FRAME_X_DISPLAY_INFO (f
), parms
, string
);
10404 f
= XFRAME (frame
);
10406 /* Set up the frame's root window. */
10407 w
= XWINDOW (FRAME_ROOT_WINDOW (f
));
10408 w
->left_col
= w
->top_line
= make_number (0);
10410 if (CONSP (Vx_max_tooltip_size
)
10411 && INTEGERP (XCAR (Vx_max_tooltip_size
))
10412 && XINT (XCAR (Vx_max_tooltip_size
)) > 0
10413 && INTEGERP (XCDR (Vx_max_tooltip_size
))
10414 && XINT (XCDR (Vx_max_tooltip_size
)) > 0)
10416 w
->total_cols
= XCAR (Vx_max_tooltip_size
);
10417 w
->total_lines
= XCDR (Vx_max_tooltip_size
);
10421 w
->total_cols
= make_number (80);
10422 w
->total_lines
= make_number (40);
10425 FRAME_TOTAL_COLS (f
) = XINT (w
->total_cols
);
10427 w
->pseudo_window_p
= 1;
10429 /* Display the tooltip text in a temporary buffer. */
10430 old_buffer
= current_buffer
;
10431 set_buffer_internal_1 (XBUFFER (XWINDOW (FRAME_ROOT_WINDOW (f
))->buffer
));
10432 current_buffer
->truncate_lines
= Qnil
;
10433 clear_glyph_matrix (w
->desired_matrix
);
10434 clear_glyph_matrix (w
->current_matrix
);
10435 SET_TEXT_POS (pos
, BEGV
, BEGV_BYTE
);
10436 try_window (FRAME_ROOT_WINDOW (f
), pos
);
10438 /* Compute width and height of the tooltip. */
10439 width
= height
= 0;
10440 for (i
= 0; i
< w
->desired_matrix
->nrows
; ++i
)
10442 struct glyph_row
*row
= &w
->desired_matrix
->rows
[i
];
10443 struct glyph
*last
;
10446 /* Stop at the first empty row at the end. */
10447 if (!row
->enabled_p
|| !row
->displays_text_p
)
10450 /* Let the row go over the full width of the frame. */
10451 row
->full_width_p
= 1;
10453 /* There's a glyph at the end of rows that is used to place
10454 the cursor there. Don't include the width of this glyph. */
10455 if (row
->used
[TEXT_AREA
])
10457 last
= &row
->glyphs
[TEXT_AREA
][row
->used
[TEXT_AREA
] - 1];
10458 row_width
= row
->pixel_width
- last
->pixel_width
;
10461 row_width
= row
->pixel_width
;
10463 height
+= row
->height
;
10464 width
= max (width
, row_width
);
10467 /* Add the frame's internal border to the width and height the X
10468 window should have. */
10469 height
+= 2 * FRAME_INTERNAL_BORDER_WIDTH (f
);
10470 width
+= 2 * FRAME_INTERNAL_BORDER_WIDTH (f
);
10472 /* Move the tooltip window where the mouse pointer is. Resize and
10474 compute_tip_xy (f
, parms
, dx
, dy
, width
, height
, &root_x
, &root_y
);
10477 XMoveResizeWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
10478 root_x
, root_y
, width
, height
);
10479 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
10482 /* Draw into the window. */
10483 w
->must_be_updated_p
= 1;
10484 update_single_window (w
, 1);
10486 /* Restore original current buffer. */
10487 set_buffer_internal_1 (old_buffer
);
10488 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
10491 /* Let the tip disappear after timeout seconds. */
10492 tip_timer
= call3 (intern ("run-at-time"), timeout
, Qnil
,
10493 intern ("x-hide-tip"));
10496 return unbind_to (count
, Qnil
);
10500 DEFUN ("x-hide-tip", Fx_hide_tip
, Sx_hide_tip
, 0, 0, 0,
10501 doc
: /* Hide the current tooltip window, if there is any.
10502 Value is t if tooltip was open, nil otherwise. */)
10506 Lisp_Object deleted
, frame
, timer
;
10507 struct gcpro gcpro1
, gcpro2
;
10509 /* Return quickly if nothing to do. */
10510 if (NILP (tip_timer
) && NILP (tip_frame
))
10515 GCPRO2 (frame
, timer
);
10516 tip_frame
= tip_timer
= deleted
= Qnil
;
10518 count
= SPECPDL_INDEX ();
10519 specbind (Qinhibit_redisplay
, Qt
);
10520 specbind (Qinhibit_quit
, Qt
);
10523 call1 (Qcancel_timer
, timer
);
10525 if (FRAMEP (frame
))
10527 Fdelete_frame (frame
, Qnil
);
10531 /* Bloodcurdling hack alert: The Lucid menu bar widget's
10532 redisplay procedure is not called when a tip frame over menu
10533 items is unmapped. Redisplay the menu manually... */
10535 struct frame
*f
= SELECTED_FRAME ();
10536 Widget w
= f
->output_data
.x
->menubar_widget
;
10537 extern void xlwmenu_redisplay
P_ ((Widget
));
10539 if (!DoesSaveUnders (FRAME_X_DISPLAY_INFO (f
)->screen
)
10543 xlwmenu_redisplay (w
);
10547 #endif /* USE_LUCID */
10551 return unbind_to (count
, deleted
);
10556 /***********************************************************************
10557 File selection dialog
10558 ***********************************************************************/
10562 /* Callback for "OK" and "Cancel" on file selection dialog. */
10565 file_dialog_cb (widget
, client_data
, call_data
)
10567 XtPointer call_data
, client_data
;
10569 int *result
= (int *) client_data
;
10570 XmAnyCallbackStruct
*cb
= (XmAnyCallbackStruct
*) call_data
;
10571 *result
= cb
->reason
;
10575 /* Callback for unmapping a file selection dialog. This is used to
10576 capture the case where a dialog is closed via a window manager's
10577 closer button, for example. Using a XmNdestroyCallback didn't work
10581 file_dialog_unmap_cb (widget
, client_data
, call_data
)
10583 XtPointer call_data
, client_data
;
10585 int *result
= (int *) client_data
;
10586 *result
= XmCR_CANCEL
;
10590 DEFUN ("x-file-dialog", Fx_file_dialog
, Sx_file_dialog
, 2, 4, 0,
10591 doc
: /* Read file name, prompting with PROMPT in directory DIR.
10592 Use a file selection dialog.
10593 Select DEFAULT-FILENAME in the dialog's file selection box, if
10594 specified. Don't let the user enter a file name in the file
10595 selection dialog's entry field, if MUSTMATCH is non-nil. */)
10596 (prompt
, dir
, default_filename
, mustmatch
)
10597 Lisp_Object prompt
, dir
, default_filename
, mustmatch
;
10600 struct frame
*f
= SELECTED_FRAME ();
10601 Lisp_Object file
= Qnil
;
10602 Widget dialog
, text
, list
, help
;
10605 extern XtAppContext Xt_app_con
;
10606 XmString dir_xmstring
, pattern_xmstring
;
10607 int count
= SPECPDL_INDEX ();
10608 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
, gcpro5
;
10610 GCPRO5 (prompt
, dir
, default_filename
, mustmatch
, file
);
10611 CHECK_STRING (prompt
);
10612 CHECK_STRING (dir
);
10614 /* Prevent redisplay. */
10615 specbind (Qinhibit_redisplay
, Qt
);
10619 /* Create the dialog with PROMPT as title, using DIR as initial
10620 directory and using "*" as pattern. */
10621 dir
= Fexpand_file_name (dir
, Qnil
);
10622 dir_xmstring
= XmStringCreateLocalized (SDATA (dir
));
10623 pattern_xmstring
= XmStringCreateLocalized ("*");
10625 XtSetArg (al
[ac
], XmNtitle
, SDATA (prompt
)); ++ac
;
10626 XtSetArg (al
[ac
], XmNdirectory
, dir_xmstring
); ++ac
;
10627 XtSetArg (al
[ac
], XmNpattern
, pattern_xmstring
); ++ac
;
10628 XtSetArg (al
[ac
], XmNresizePolicy
, XmRESIZE_GROW
); ++ac
;
10629 XtSetArg (al
[ac
], XmNdialogStyle
, XmDIALOG_APPLICATION_MODAL
); ++ac
;
10630 dialog
= XmCreateFileSelectionDialog (f
->output_data
.x
->widget
,
10632 XmStringFree (dir_xmstring
);
10633 XmStringFree (pattern_xmstring
);
10635 /* Add callbacks for OK and Cancel. */
10636 XtAddCallback (dialog
, XmNokCallback
, file_dialog_cb
,
10637 (XtPointer
) &result
);
10638 XtAddCallback (dialog
, XmNcancelCallback
, file_dialog_cb
,
10639 (XtPointer
) &result
);
10640 XtAddCallback (dialog
, XmNunmapCallback
, file_dialog_unmap_cb
,
10641 (XtPointer
) &result
);
10643 /* Disable the help button since we can't display help. */
10644 help
= XmFileSelectionBoxGetChild (dialog
, XmDIALOG_HELP_BUTTON
);
10645 XtSetSensitive (help
, False
);
10647 /* Mark OK button as default. */
10648 XtVaSetValues (XmFileSelectionBoxGetChild (dialog
, XmDIALOG_OK_BUTTON
),
10649 XmNshowAsDefault
, True
, NULL
);
10651 /* If MUSTMATCH is non-nil, disable the file entry field of the
10652 dialog, so that the user must select a file from the files list
10653 box. We can't remove it because we wouldn't have a way to get at
10654 the result file name, then. */
10655 text
= XmFileSelectionBoxGetChild (dialog
, XmDIALOG_TEXT
);
10656 if (!NILP (mustmatch
))
10659 label
= XmFileSelectionBoxGetChild (dialog
, XmDIALOG_SELECTION_LABEL
);
10660 XtSetSensitive (text
, False
);
10661 XtSetSensitive (label
, False
);
10664 /* Manage the dialog, so that list boxes get filled. */
10665 XtManageChild (dialog
);
10667 /* Select DEFAULT_FILENAME in the files list box. DEFAULT_FILENAME
10668 must include the path for this to work. */
10669 list
= XmFileSelectionBoxGetChild (dialog
, XmDIALOG_LIST
);
10670 if (STRINGP (default_filename
))
10672 XmString default_xmstring
;
10676 = XmStringCreateLocalized (SDATA (default_filename
));
10678 if (!XmListItemExists (list
, default_xmstring
))
10680 /* Add a new item if DEFAULT_FILENAME is not in the list. */
10681 XmListAddItem (list
, default_xmstring
, 0);
10685 item_pos
= XmListItemPos (list
, default_xmstring
);
10686 XmStringFree (default_xmstring
);
10688 /* Select the item and scroll it into view. */
10689 XmListSelectPos (list
, item_pos
, True
);
10690 XmListSetPos (list
, item_pos
);
10693 /* Process events until the user presses Cancel or OK. */
10695 while (result
== 0)
10698 XtAppNextEvent (Xt_app_con
, &event
);
10699 (void) x_dispatch_event (&event
, FRAME_X_DISPLAY (f
) );
10702 /* Get the result. */
10703 if (result
== XmCR_OK
)
10708 XtVaGetValues (dialog
, XmNtextString
, &text
, NULL
);
10709 XmStringGetLtoR (text
, XmFONTLIST_DEFAULT_TAG
, &data
);
10710 XmStringFree (text
);
10711 file
= build_string (data
);
10718 XtUnmanageChild (dialog
);
10719 XtDestroyWidget (dialog
);
10723 /* Make "Cancel" equivalent to C-g. */
10725 Fsignal (Qquit
, Qnil
);
10727 return unbind_to (count
, file
);
10730 #endif /* USE_MOTIF */
10734 DEFUN ("x-file-dialog", Fx_file_dialog
, Sx_file_dialog
, 2, 4, 0,
10735 "Read file name, prompting with PROMPT in directory DIR.\n\
10736 Use a file selection dialog.\n\
10737 Select DEFAULT-FILENAME in the dialog's file selection box, if\n\
10738 specified. Don't let the user enter a file name in the file\n\
10739 selection dialog's entry field, if MUSTMATCH is non-nil.")
10740 (prompt
, dir
, default_filename
, mustmatch
)
10741 Lisp_Object prompt
, dir
, default_filename
, mustmatch
;
10743 FRAME_PTR f
= SELECTED_FRAME ();
10745 Lisp_Object file
= Qnil
;
10746 int count
= specpdl_ptr
- specpdl
;
10747 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
, gcpro5
;
10751 GCPRO5 (prompt
, dir
, default_filename
, mustmatch
, file
);
10752 CHECK_STRING (prompt
);
10753 CHECK_STRING (dir
);
10755 /* Prevent redisplay. */
10756 specbind (Qinhibit_redisplay
, Qt
);
10760 if (STRINGP (default_filename
))
10761 cdef_file
= SDATA (default_filename
);
10763 cdef_file
= SDATA (dir
);
10765 fn
= xg_get_file_name (f
, SDATA (prompt
), cdef_file
, ! NILP (mustmatch
));
10769 file
= build_string (fn
);
10776 /* Make "Cancel" equivalent to C-g. */
10778 Fsignal (Qquit
, Qnil
);
10780 return unbind_to (count
, file
);
10783 #endif /* USE_GTK */
10786 /***********************************************************************
10788 ***********************************************************************/
10790 #ifdef HAVE_XKBGETKEYBOARD
10791 #include <X11/XKBlib.h>
10792 #include <X11/keysym.h>
10795 DEFUN ("x-backspace-delete-keys-p", Fx_backspace_delete_keys_p
,
10796 Sx_backspace_delete_keys_p
, 0, 1, 0,
10797 doc
: /* Check if both Backspace and Delete keys are on the keyboard of FRAME.
10798 FRAME nil means use the selected frame.
10799 Value is t if we know that both keys are present, and are mapped to the
10800 usual X keysyms. */)
10804 #ifdef HAVE_XKBGETKEYBOARD
10806 struct frame
*f
= check_x_frame (frame
);
10807 Display
*dpy
= FRAME_X_DISPLAY (f
);
10808 Lisp_Object have_keys
;
10809 int major
, minor
, op
, event
, error
;
10813 /* Check library version in case we're dynamically linked. */
10814 major
= XkbMajorVersion
;
10815 minor
= XkbMinorVersion
;
10816 if (!XkbLibraryVersion (&major
, &minor
))
10822 /* Check that the server supports XKB. */
10823 major
= XkbMajorVersion
;
10824 minor
= XkbMinorVersion
;
10825 if (!XkbQueryExtension (dpy
, &op
, &event
, &error
, &major
, &minor
))
10832 kb
= XkbGetMap (dpy
, XkbAllMapComponentsMask
, XkbUseCoreKbd
);
10835 int delete_keycode
= 0, backspace_keycode
= 0, i
;
10837 if (XkbGetNames (dpy
, XkbAllNamesMask
, kb
) == Success
)
10839 for (i
= kb
->min_key_code
;
10840 (i
< kb
->max_key_code
10841 && (delete_keycode
== 0 || backspace_keycode
== 0));
10844 /* The XKB symbolic key names can be seen most easily in
10845 the PS file generated by `xkbprint -label name
10847 if (bcmp ("DELE", kb
->names
->keys
[i
].name
, 4) == 0)
10848 delete_keycode
= i
;
10849 else if (bcmp ("BKSP", kb
->names
->keys
[i
].name
, 4) == 0)
10850 backspace_keycode
= i
;
10853 XkbFreeNames (kb
, 0, True
);
10856 XkbFreeClientMap (kb
, 0, True
);
10859 && backspace_keycode
10860 && XKeysymToKeycode (dpy
, XK_Delete
) == delete_keycode
10861 && XKeysymToKeycode (dpy
, XK_BackSpace
) == backspace_keycode
)
10866 #else /* not HAVE_XKBGETKEYBOARD */
10868 #endif /* not HAVE_XKBGETKEYBOARD */
10873 /***********************************************************************
10875 ***********************************************************************/
10877 /* Keep this list in the same order as frame_parms in frame.c.
10878 Use 0 for unsupported frame parameters. */
10880 frame_parm_handler x_frame_parm_handlers
[] =
10884 x_set_background_color
,
10885 x_set_border_color
,
10886 x_set_border_width
,
10887 x_set_cursor_color
,
10890 x_set_foreground_color
,
10893 x_set_internal_border_width
,
10894 x_set_menu_bar_lines
,
10896 x_explicitly_set_name
,
10897 x_set_scroll_bar_width
,
10899 x_set_unsplittable
,
10900 x_set_vertical_scroll_bars
,
10902 x_set_tool_bar_lines
,
10903 x_set_scroll_bar_foreground
,
10904 x_set_scroll_bar_background
,
10905 x_set_screen_gamma
,
10906 x_set_line_spacing
,
10907 x_set_fringe_width
,
10908 x_set_fringe_width
,
10916 /* This is zero if not using X windows. */
10919 /* The section below is built by the lisp expression at the top of the file,
10920 just above where these variables are declared. */
10921 /*&&& init symbols here &&&*/
10922 Qnone
= intern ("none");
10923 staticpro (&Qnone
);
10924 Qsuppress_icon
= intern ("suppress-icon");
10925 staticpro (&Qsuppress_icon
);
10926 Qundefined_color
= intern ("undefined-color");
10927 staticpro (&Qundefined_color
);
10928 Qcenter
= intern ("center");
10929 staticpro (&Qcenter
);
10930 Qcompound_text
= intern ("compound-text");
10931 staticpro (&Qcompound_text
);
10932 Qcancel_timer
= intern ("cancel-timer");
10933 staticpro (&Qcancel_timer
);
10934 /* This is the end of symbol initialization. */
10936 /* Text property `display' should be nonsticky by default. */
10937 Vtext_property_default_nonsticky
10938 = Fcons (Fcons (Qdisplay
, Qt
), Vtext_property_default_nonsticky
);
10941 Qlaplace
= intern ("laplace");
10942 staticpro (&Qlaplace
);
10943 Qemboss
= intern ("emboss");
10944 staticpro (&Qemboss
);
10945 Qedge_detection
= intern ("edge-detection");
10946 staticpro (&Qedge_detection
);
10947 Qheuristic
= intern ("heuristic");
10948 staticpro (&Qheuristic
);
10949 QCmatrix
= intern (":matrix");
10950 staticpro (&QCmatrix
);
10951 QCcolor_adjustment
= intern (":color-adjustment");
10952 staticpro (&QCcolor_adjustment
);
10953 QCmask
= intern (":mask");
10954 staticpro (&QCmask
);
10956 Fput (Qundefined_color
, Qerror_conditions
,
10957 Fcons (Qundefined_color
, Fcons (Qerror
, Qnil
)));
10958 Fput (Qundefined_color
, Qerror_message
,
10959 build_string ("Undefined color"));
10961 DEFVAR_BOOL ("cross-disabled-images", &cross_disabled_images
,
10962 doc
: /* Non-nil means always draw a cross over disabled images.
10963 Disabled images are those having an `:conversion disabled' property.
10964 A cross is always drawn on black & white displays. */);
10965 cross_disabled_images
= 0;
10967 DEFVAR_LISP ("x-bitmap-file-path", &Vx_bitmap_file_path
,
10968 doc
: /* List of directories to search for window system bitmap files. */);
10969 Vx_bitmap_file_path
= decode_env_path ((char *) 0, PATH_BITMAPS
);
10971 DEFVAR_LISP ("x-pointer-shape", &Vx_pointer_shape
,
10972 doc
: /* The shape of the pointer when over text.
10973 Changing the value does not affect existing frames
10974 unless you set the mouse color. */);
10975 Vx_pointer_shape
= Qnil
;
10977 #if 0 /* This doesn't really do anything. */
10978 DEFVAR_LISP ("x-nontext-pointer-shape", &Vx_nontext_pointer_shape
,
10979 doc
: /* The shape of the pointer when not over text.
10980 This variable takes effect when you create a new frame
10981 or when you set the mouse color. */);
10983 Vx_nontext_pointer_shape
= Qnil
;
10985 DEFVAR_LISP ("x-hourglass-pointer-shape", &Vx_hourglass_pointer_shape
,
10986 doc
: /* The shape of the pointer when Emacs is busy.
10987 This variable takes effect when you create a new frame
10988 or when you set the mouse color. */);
10989 Vx_hourglass_pointer_shape
= Qnil
;
10991 DEFVAR_BOOL ("display-hourglass", &display_hourglass_p
,
10992 doc
: /* Non-zero means Emacs displays an hourglass pointer on window systems. */);
10993 display_hourglass_p
= 1;
10995 DEFVAR_LISP ("hourglass-delay", &Vhourglass_delay
,
10996 doc
: /* *Seconds to wait before displaying an hourglass pointer.
10997 Value must be an integer or float. */);
10998 Vhourglass_delay
= make_number (DEFAULT_HOURGLASS_DELAY
);
11000 #if 0 /* This doesn't really do anything. */
11001 DEFVAR_LISP ("x-mode-pointer-shape", &Vx_mode_pointer_shape
,
11002 doc
: /* The shape of the pointer when over the mode line.
11003 This variable takes effect when you create a new frame
11004 or when you set the mouse color. */);
11006 Vx_mode_pointer_shape
= Qnil
;
11008 DEFVAR_LISP ("x-sensitive-text-pointer-shape",
11009 &Vx_sensitive_text_pointer_shape
,
11010 doc
: /* The shape of the pointer when over mouse-sensitive text.
11011 This variable takes effect when you create a new frame
11012 or when you set the mouse color. */);
11013 Vx_sensitive_text_pointer_shape
= Qnil
;
11015 DEFVAR_LISP ("x-window-horizontal-drag-cursor",
11016 &Vx_window_horizontal_drag_shape
,
11017 doc
: /* Pointer shape to use for indicating a window can be dragged horizontally.
11018 This variable takes effect when you create a new frame
11019 or when you set the mouse color. */);
11020 Vx_window_horizontal_drag_shape
= Qnil
;
11022 DEFVAR_LISP ("x-cursor-fore-pixel", &Vx_cursor_fore_pixel
,
11023 doc
: /* A string indicating the foreground color of the cursor box. */);
11024 Vx_cursor_fore_pixel
= Qnil
;
11026 DEFVAR_LISP ("x-max-tooltip-size", &Vx_max_tooltip_size
,
11027 doc
: /* Maximum size for tooltips. Value is a pair (COLUMNS . ROWS).
11028 Text larger than this is clipped. */);
11029 Vx_max_tooltip_size
= Fcons (make_number (80), make_number (40));
11031 DEFVAR_LISP ("x-no-window-manager", &Vx_no_window_manager
,
11032 doc
: /* Non-nil if no X window manager is in use.
11033 Emacs doesn't try to figure this out; this is always nil
11034 unless you set it to something else. */);
11035 /* We don't have any way to find this out, so set it to nil
11036 and maybe the user would like to set it to t. */
11037 Vx_no_window_manager
= Qnil
;
11039 DEFVAR_LISP ("x-pixel-size-width-font-regexp",
11040 &Vx_pixel_size_width_font_regexp
,
11041 doc
: /* Regexp matching a font name whose width is the same as `PIXEL_SIZE'.
11043 Since Emacs gets width of a font matching with this regexp from
11044 PIXEL_SIZE field of the name, font finding mechanism gets faster for
11045 such a font. This is especially effective for such large fonts as
11046 Chinese, Japanese, and Korean. */);
11047 Vx_pixel_size_width_font_regexp
= Qnil
;
11049 DEFVAR_LISP ("image-cache-eviction-delay", &Vimage_cache_eviction_delay
,
11050 doc
: /* Time after which cached images are removed from the cache.
11051 When an image has not been displayed this many seconds, remove it
11052 from the image cache. Value must be an integer or nil with nil
11053 meaning don't clear the cache. */);
11054 Vimage_cache_eviction_delay
= make_number (30 * 60);
11056 #ifdef USE_X_TOOLKIT
11057 Fprovide (intern ("x-toolkit"), Qnil
);
11059 Fprovide (intern ("motif"), Qnil
);
11061 DEFVAR_LISP ("motif-version-string", &Vmotif_version_string
,
11062 doc
: /* Version info for LessTif/Motif. */);
11063 Vmotif_version_string
= build_string (XmVERSION_STRING
);
11064 #endif /* USE_MOTIF */
11065 #endif /* USE_X_TOOLKIT */
11068 Fprovide (intern ("gtk"), Qnil
);
11070 DEFVAR_LISP ("gtk-version-string", &Vgtk_version_string
,
11071 doc
: /* Version info for GTK+. */);
11073 char gtk_version
[40];
11074 g_snprintf (gtk_version
, sizeof (gtk_version
), "%u.%u.%u",
11075 GTK_MAJOR_VERSION
, GTK_MINOR_VERSION
, GTK_MICRO_VERSION
);
11076 Vgtk_version_string
= build_string (gtk_version
);
11078 #endif /* USE_GTK */
11080 /* X window properties. */
11081 defsubr (&Sx_change_window_property
);
11082 defsubr (&Sx_delete_window_property
);
11083 defsubr (&Sx_window_property
);
11085 defsubr (&Sxw_display_color_p
);
11086 defsubr (&Sx_display_grayscale_p
);
11087 defsubr (&Sxw_color_defined_p
);
11088 defsubr (&Sxw_color_values
);
11089 defsubr (&Sx_server_max_request_size
);
11090 defsubr (&Sx_server_vendor
);
11091 defsubr (&Sx_server_version
);
11092 defsubr (&Sx_display_pixel_width
);
11093 defsubr (&Sx_display_pixel_height
);
11094 defsubr (&Sx_display_mm_width
);
11095 defsubr (&Sx_display_mm_height
);
11096 defsubr (&Sx_display_screens
);
11097 defsubr (&Sx_display_planes
);
11098 defsubr (&Sx_display_color_cells
);
11099 defsubr (&Sx_display_visual_class
);
11100 defsubr (&Sx_display_backing_store
);
11101 defsubr (&Sx_display_save_under
);
11102 defsubr (&Sx_create_frame
);
11103 defsubr (&Sx_open_connection
);
11104 defsubr (&Sx_close_connection
);
11105 defsubr (&Sx_display_list
);
11106 defsubr (&Sx_synchronize
);
11107 defsubr (&Sx_send_client_message
);
11108 defsubr (&Sx_focus_frame
);
11109 defsubr (&Sx_backspace_delete_keys_p
);
11111 /* Setting callback functions for fontset handler. */
11112 get_font_info_func
= x_get_font_info
;
11114 #if 0 /* This function pointer doesn't seem to be used anywhere.
11115 And the pointer assigned has the wrong type, anyway. */
11116 list_fonts_func
= x_list_fonts
;
11119 load_font_func
= x_load_font
;
11120 find_ccl_program_func
= x_find_ccl_program
;
11121 query_font_func
= x_query_font
;
11122 set_frame_fontset_func
= x_set_font
;
11123 check_window_system_func
= check_x
;
11126 Qxbm
= intern ("xbm");
11128 QCconversion
= intern (":conversion");
11129 staticpro (&QCconversion
);
11130 QCheuristic_mask
= intern (":heuristic-mask");
11131 staticpro (&QCheuristic_mask
);
11132 QCcolor_symbols
= intern (":color-symbols");
11133 staticpro (&QCcolor_symbols
);
11134 QCascent
= intern (":ascent");
11135 staticpro (&QCascent
);
11136 QCmargin
= intern (":margin");
11137 staticpro (&QCmargin
);
11138 QCrelief
= intern (":relief");
11139 staticpro (&QCrelief
);
11140 Qpostscript
= intern ("postscript");
11141 staticpro (&Qpostscript
);
11142 QCloader
= intern (":loader");
11143 staticpro (&QCloader
);
11144 QCbounding_box
= intern (":bounding-box");
11145 staticpro (&QCbounding_box
);
11146 QCpt_width
= intern (":pt-width");
11147 staticpro (&QCpt_width
);
11148 QCpt_height
= intern (":pt-height");
11149 staticpro (&QCpt_height
);
11150 QCindex
= intern (":index");
11151 staticpro (&QCindex
);
11152 Qpbm
= intern ("pbm");
11156 Qxpm
= intern ("xpm");
11161 Qjpeg
= intern ("jpeg");
11162 staticpro (&Qjpeg
);
11166 Qtiff
= intern ("tiff");
11167 staticpro (&Qtiff
);
11171 Qgif
= intern ("gif");
11176 Qpng
= intern ("png");
11180 defsubr (&Sclear_image_cache
);
11181 defsubr (&Simage_size
);
11182 defsubr (&Simage_mask_p
);
11184 hourglass_atimer
= NULL
;
11185 hourglass_shown_p
= 0;
11187 defsubr (&Sx_show_tip
);
11188 defsubr (&Sx_hide_tip
);
11190 staticpro (&tip_timer
);
11192 staticpro (&tip_frame
);
11194 last_show_tip_args
= Qnil
;
11195 staticpro (&last_show_tip_args
);
11198 defsubr (&Sx_file_dialog
);
11206 image_types
= NULL
;
11207 Vimage_types
= Qnil
;
11209 define_image_type (&xbm_type
);
11210 define_image_type (&gs_type
);
11211 define_image_type (&pbm_type
);
11214 define_image_type (&xpm_type
);
11218 define_image_type (&jpeg_type
);
11222 define_image_type (&tiff_type
);
11226 define_image_type (&gif_type
);
11230 define_image_type (&png_type
);
11234 #endif /* HAVE_X_WINDOWS */
11236 /* arch-tag: 55040d02-5485-4d58-8b22-95a7a05f3288
11237 (do not change this comment) */