2 Copyright (C) 1993 Free Software Foundation.
4 This file is part of GNU Emacs.
6 GNU Emacs is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU Emacs is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Emacs; see the file COPYING. If not, write to
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
20 /* This is derived from work by Lucid (some parts very loosely so). */
22 #include <sys/types.h>
32 #include "dispextern.h"
34 #include "blockinput.h"
37 /* Compensate for bug in Xos.h on some systems. */
38 #ifdef XOS_NEEDS_TIME_H
43 /* These don't seem to be used. */
45 /* Display Context for the icons */
46 #include <X11/Intrinsic.h>
47 #include <X11/StringDefs.h>
48 #include <X11/Xmu/Drawing.h>
54 /* An explanation of the face data structures. */
56 /* ========================= Face Data Structures =========================
58 All lisp code uses symbols as face names.
60 Each frame has a face_alist member (with the frame-face-alist and
61 set-frame-face-alist accessors), associating the face names with
63 [face NAME ID FONT FOREGROUND BACKGROUND BACKGROUND-PIXMAP UNDERLINE-P]
65 face is the symbol `face',
66 NAME is the symbol with which this vector is associated (a backpointer),
67 ID is the face ID, an integer used internally by the C code to identify
69 FONT, FOREGROUND, and BACKGROUND are strings naming the fonts and colors
71 BACKGROUND-PIXMAP is the name of an x bitmap filename, which we don't
73 UNDERLINE-P is non-nil if the face should be underlined.
74 If any of these elements are nil, that allows the frame's parameters to
76 (lisp/faces.el maintains these association lists.)
78 The frames' private alists hold the frame-local definitions for the
79 faces. The lisp variable global-face-data contains the global
80 defaults for faces. (See lisp/faces.el for this too.)
82 In the C code, we also have a `struct face' with the elements
83 `foreground', `background', `font', and `underline',
84 which specify its visual appearance, and elements
85 `gc' and `cached_index';
86 `gc' may be an X GC which has been built for the given display
87 parameters. Faces with GC's are called `display faces'. Whether
88 or not a face has a GC depends on what data structure the face is
89 in; we explain these more below. (See src/dispextern.h.)
91 Each frame also has members called `faces' and `n_faces' (with the
92 accessors FRAME_FACES and FRAME_N_FACES), which define an array of
93 struct face pointers, indexed by face ID (element 2 of the
94 vector). These are called "frame faces".
95 Element 0 is the default face --- the one used for normal text.
96 Element 1 is the modeline face.
97 These faces have their GC's set; the rest do not.
98 If faces[i] is filled in (i.e. non-zero) on one frame, then it must
99 be filled in on all frames. Code assumes that face ID's can be
100 used on any frame. (See src/xterm.h.)
102 The global variables `face_vector' and `nfaces' define another
103 array of struct face pointers, with their GC's set. This array
104 acts as a cache of GC's to be used by all frames. The function
105 `intern_face', passed a struct face *, searches face_vector for a
106 struct face with the same parameters, adds a new one with a GC if
107 it doesn't find one, and returns it. If you have a `struct face',
108 and you want a GC for it, call intern_face on that struct, and it
109 will return a `struct face *' with its GC set. The faces in
110 face_vector are called `cached faces.' (See src/xfaces.c.)
112 The `GLYPH' data type is an unsigned integer type; the bottom byte
113 is a character code, and the byte above that is a face id. The
114 `struct frame_glyphs' structure, used to describe frames' current
115 or desired contents, is essentially a matrix of GLYPHs; the face
116 ID's in a struct frame_glyphs are indices into FRAME_FACES. (See
121 Since face_vector is just a cache --- there are no pointers into it
122 from the rest of the code, and everyone accesses it through
123 intern_face --- we could just free its GC's and throw the whole
124 thing away without breaking anything. This gives us a simple way
125 to garbage-collect old GC's nobody's using any more - we can just
126 purge face_vector, and then let subsequent calls to intern_face
127 refill it as needed. The function clear_face_vector performs this
130 We're often applying intern_face to faces in frames' local arrays -
131 for example, we do this while sending GLYPHs from a struct
132 frame_glyphs to X during redisplay. It would be nice to avoid
133 searching all of face_vector every time we intern a frame's face.
134 So, when intern_face finds a match for FACE in face_vector, it
135 stores the index of the match in FACE's cached_index member, and
136 checks there first next time. */
139 /* Definitions and declarations. */
141 /* A table of display faces. */
142 struct face
**face_vector
;
143 /* The length in use of the table. */
145 /* The allocated length of the table. */
146 int nfaces_allocated
;
148 /* The number of face-id's in use (same for all frames). */
151 /* The number of the face to use to indicate the region. */
154 /* This is what appears in a slot in a face to signify that the face
155 does not specify that display aspect. */
156 #define FACE_DEFAULT (~0)
158 Lisp_Object Qface
, Qwindow
, Qpriority
;
160 static void build_face ();
161 int face_name_id_number ();
163 struct face
*intern_face ();
164 static void ensure_face_ready ();
166 /* Allocating, copying, and comparing struct faces. */
168 /* Allocate a new face */
172 struct face
*result
= (struct face
*) xmalloc (sizeof (struct face
));
173 bzero (result
, sizeof (struct face
));
174 result
->font
= (XFontStruct
*) FACE_DEFAULT
;
175 result
->foreground
= FACE_DEFAULT
;
176 result
->background
= FACE_DEFAULT
;
177 result
->stipple
= FACE_DEFAULT
;
181 /* Make a new face that's a copy of an existing one. */
186 struct face
*result
= allocate_face ();
188 result
->font
= face
->font
;
189 result
->foreground
= face
->foreground
;
190 result
->background
= face
->background
;
191 result
->stipple
= face
->stipple
;
192 result
->underline
= face
->underline
;
198 face_eql (face1
, face2
)
199 struct face
*face1
, *face2
;
201 return ( face1
->font
== face2
->font
202 && face1
->foreground
== face2
->foreground
203 && face1
->background
== face2
->background
204 && face1
->stipple
== face2
->stipple
205 && face1
->underline
== face2
->underline
);
208 /* Interning faces in the `face_vector' cache, and clearing that cache. */
210 /* Return the unique display face corresponding to the user-level face FACE.
211 If there isn't one, make one, and find a slot in the face_vector to
214 get_cached_face (f
, face
)
221 /* Perhaps FACE->cached_index is valid; this could happen if FACE is
222 in a frame's face list. */
223 if (face
->cached_index
>= 0
224 && face
->cached_index
< nfaces
225 && face_eql (face_vector
[face
->cached_index
], face
))
226 return face_vector
[face
->cached_index
];
228 /* Look for an existing display face that does the job.
229 Also find an empty slot if any. */
230 for (i
= 0; i
< nfaces
; i
++)
232 if (face_eql (face_vector
[i
], face
))
233 return face_vector
[i
];
234 if (face_vector
[i
] == 0)
238 /* If no empty slots, make one. */
239 if (empty
< 0 && nfaces
== nfaces_allocated
)
241 int newsize
= nfaces
+ 20;
243 = (struct face
**) xrealloc (face_vector
,
244 newsize
* sizeof (struct face
*));
245 nfaces_allocated
= newsize
;
251 /* Put a new display face in the empty slot. */
252 result
= copy_face (face
);
253 face_vector
[empty
] = result
;
255 /* Make a graphics context for it. */
256 build_face (f
, result
);
261 /* Given a frame face, return an equivalent display face
262 (one which has a graphics context). */
265 intern_face (f
, face
)
269 /* If it's equivalent to the default face, use that. */
270 if (face_eql (face
, FRAME_DEFAULT_FACE (f
)))
272 if (!FRAME_DEFAULT_FACE (f
)->gc
)
273 build_face (f
, FRAME_DEFAULT_FACE (f
));
274 return FRAME_DEFAULT_FACE (f
);
277 /* If it's equivalent to the mode line face, use that. */
278 if (face_eql (face
, FRAME_MODE_LINE_FACE (f
)))
280 if (!FRAME_MODE_LINE_FACE (f
)->gc
)
281 build_face (f
, FRAME_MODE_LINE_FACE (f
));
282 return FRAME_MODE_LINE_FACE (f
);
285 /* If it's not one of the frame's default faces, it shouldn't have a GC. */
289 /* Get a specialized display face. */
290 return get_cached_face (f
, face
);
293 /* Clear out face_vector and start anew.
294 This should be done from time to time just to avoid
295 keeping too many graphics contexts in face_vector
296 that are no longer needed. */
302 Display
*dpy
= x_current_display
;
306 /* Free the display faces in the face_vector. */
307 for (i
= 0; i
< nfaces
; i
++)
309 struct face
*face
= face_vector
[i
];
311 XFreeGC (dpy
, face
->gc
);
319 /* Allocating and freeing X resources for display faces. */
321 /* Make a graphics context for face FACE, which is on frame F,
322 if that can be done. */
334 if (face
->foreground
!= FACE_DEFAULT
)
335 xgcv
.foreground
= face
->foreground
;
337 xgcv
.foreground
= f
->display
.x
->foreground_pixel
;
339 if (face
->background
!= FACE_DEFAULT
)
340 xgcv
.background
= face
->background
;
342 xgcv
.background
= f
->display
.x
->background_pixel
;
344 if (face
->font
&& (int) face
->font
!= FACE_DEFAULT
)
345 xgcv
.font
= face
->font
->fid
;
347 xgcv
.font
= f
->display
.x
->font
->fid
;
349 xgcv
.graphics_exposures
= 0;
351 mask
= GCForeground
| GCBackground
| GCFont
| GCGraphicsExposures
;
352 gc
= XCreateGC (x_current_display
, FRAME_X_WINDOW (f
),
356 if (face
->stipple
&& face
->stipple
!= FACE_DEFAULT
)
357 XSetStipple (x_current_display
, gc
, face
->stipple
);
365 /* Allocating, freeing, and duplicating fonts, colors, and pixmaps. */
375 return (XFontStruct
*) FACE_DEFAULT
;
377 CHECK_STRING (name
, 0);
379 font
= XLoadQueryFont (x_current_display
, (char *) XSTRING (name
)->data
);
383 Fsignal (Qerror
, Fcons (build_string ("undefined font"),
384 Fcons (name
, Qnil
)));
389 unload_font (f
, font
)
393 if (!font
|| font
== ((XFontStruct
*) FACE_DEFAULT
))
397 XFreeFont (x_current_display
, font
);
406 Display
*dpy
= x_current_display
;
414 cmap
= DefaultColormapOfScreen (DefaultScreenOfDisplay (x_current_display
));
416 CHECK_STRING (name
, 0);
418 result
= XParseColor (dpy
, cmap
, (char *) XSTRING (name
)->data
, &color
);
421 Fsignal (Qerror
, Fcons (build_string ("undefined color"),
422 Fcons (name
, Qnil
)));
424 result
= XAllocColor (dpy
, cmap
, &color
);
427 Fsignal (Qerror
, Fcons (build_string ("X server cannot allocate color"),
428 Fcons (name
, Qnil
)));
429 return (unsigned long) color
.pixel
;
433 unload_color (f
, pixel
)
437 /* Since faces get built by copying parameters from other faces, the
438 allocation counts for the colors get all screwed up. I don't see
439 any solution that will take less than 10 minutes, and it's better
440 to have a color leak than a crash, so I'm just dyking this out.
441 This isn't really a color leak, anyway - if we ask for it again,
442 we'll get the same pixel. */
445 Display
*dpy
= x_current_display
;
446 if (pixel
== FACE_DEFAULT
447 || pixel
== BLACK_PIX_DEFAULT
448 || pixel
== WHITE_PIX_DEFAULT
)
450 cmap
= DefaultColormapOfScreen (DefaultScreenOfDisplay (x_current_display
));
452 XFreeColors (dpy
, cmap
, &pixel
, 1, 0);
457 /* Initializing face arrays for frames. */
463 ensure_face_ready (f
, 0);
464 ensure_face_ready (f
, 1);
466 recompute_basic_faces (f
);
468 /* Find another X frame. */
470 Lisp_Object tail
, frame
, result
;
473 FOR_EACH_FRAME (tail
, frame
)
474 if (FRAME_X_P (XFRAME (frame
))
475 && XFRAME (frame
) != f
)
481 /* If we didn't find any X frames other than f, then we don't need
482 any faces other than 0 and 1, so we're okay. Otherwise, make
483 sure that all faces valid on the selected frame are also valid
484 on this new frame. */
488 int n_faces
= XFRAME (result
)->display
.x
->n_faces
;
489 struct face
**faces
= XFRAME (result
)->display
.x
->faces
;
491 for (i
= 2; i
< n_faces
; i
++)
493 ensure_face_ready (f
, i
);
499 /* Called from Fdelete_frame. */
504 Display
*dpy
= x_current_display
;
509 for (i
= 0; i
< FRAME_N_FACES (f
); i
++)
511 struct face
*face
= FRAME_FACES (f
) [i
];
515 XFreeGC (dpy
, face
->gc
);
518 unload_font (f
, face
->font
);
519 unload_color (f
, face
->foreground
);
520 unload_color (f
, face
->background
);
522 unload_pixmap (f
, face
->stipple
);
528 xfree (FRAME_FACES (f
));
530 FRAME_N_FACES (f
) = 0;
535 /* Interning faces in a frame's face array. */
537 /* Find a match for NEW_FACE in a FRAME's face array, and add it if we don't
540 intern_frame_face (frame
, new_face
)
542 struct face
*new_face
;
544 int len
= FRAME_N_FACES (frame
);
547 /* Search for a face already on FRAME equivalent to FACE. */
548 for (i
= 0; i
< len
; i
++)
550 struct face
*frame_face
= FRAME_FACES (frame
)[i
];
552 if (frame_face
&& face_eql (new_face
, frame_face
))
556 /* We didn't find one; add a new one. */
559 ensure_face_ready (frame
, i
);
560 bcopy (new_face
, FRAME_FACES (frame
)[i
], sizeof (*new_face
));
561 FRAME_FACES (frame
)[i
]->copy
= 1;
566 /* Make face id ID valid on frame F. */
569 ensure_face_ready (f
, id
)
573 if (FRAME_N_FACES (f
) <= id
)
577 if (!FRAME_N_FACES (f
))
579 = (struct face
**) xmalloc (sizeof (struct face
*) * n
);
582 = (struct face
**) xrealloc (FRAME_FACES (f
),
583 sizeof (struct face
*) * n
);
585 bzero (FRAME_FACES (f
) + FRAME_N_FACES (f
),
586 (n
- FRAME_N_FACES (f
)) * sizeof (struct face
*));
587 FRAME_N_FACES (f
) = n
;
590 if (FRAME_FACES (f
) [id
] == 0)
591 FRAME_FACES (f
) [id
] = allocate_face ();
594 /* Computing faces appropriate for a given piece of text in a buffer. */
596 /* Return non-zero if FONT1 and FONT2 have the same size bounding box.
597 We assume that they're both character-cell fonts. */
599 same_size_fonts (font1
, font2
)
600 XFontStruct
*font1
, *font2
;
602 XCharStruct
*bounds1
= &font1
->min_bounds
;
603 XCharStruct
*bounds2
= &font2
->min_bounds
;
605 return (bounds1
->width
== bounds2
->width
);
606 /* Checking the following caused bad results in some cases
607 when fonts that should be the same size
608 actually have very slightly different size.
609 It is possible that this reintroduces the bug whereby line positions
610 were not right. However, the right way to fix that is to change xterm.c
611 so that the vertical positions of lines
612 depend only on the height of the frame's font.
613 && bounds1->ascent == bounds2->ascent
614 && bounds1->descent == bounds2->descent); */
617 /* Modify face TO by copying from FROM all properties which have
618 nondefault settings. */
620 merge_faces (from
, to
)
621 struct face
*from
, *to
;
623 /* Only merge the font if it's the same size as the base font. */
624 if (from
->font
!= (XFontStruct
*) FACE_DEFAULT
625 && same_size_fonts (from
->font
, to
->font
))
626 to
->font
= from
->font
;
627 if (from
->foreground
!= FACE_DEFAULT
)
628 to
->foreground
= from
->foreground
;
629 if (from
->background
!= FACE_DEFAULT
)
630 to
->background
= from
->background
;
631 if (from
->stipple
!= FACE_DEFAULT
)
632 to
->stipple
= from
->stipple
;
634 to
->underline
= from
->underline
;
637 /* Set up the basic set of facial parameters, based on the frame's
638 data; all faces are deltas applied to this. */
640 compute_base_face (f
, face
)
644 struct x_display
*d
= f
->display
.x
;
647 face
->foreground
= d
->foreground_pixel
;
648 face
->background
= d
->background_pixel
;
649 face
->font
= d
->font
;
653 /* Avoid a face comparison by making this invalid. */
654 face
->cached_index
= -1;
666 sort_overlays (s1
, s2
)
667 struct sortvec
*s1
, *s2
;
669 if (s1
->priority
!= s2
->priority
)
670 return s1
->priority
- s2
->priority
;
671 if (s1
->beg
!= s2
->beg
)
672 return s1
->beg
- s2
->beg
;
673 if (s1
->end
!= s2
->end
)
674 return s2
->end
- s1
->end
;
678 /* Return the face ID associated with a buffer position POS.
679 Store into *ENDPTR the position at which a different face is needed.
680 This does not take account of glyphs that specify their own face codes.
681 F is the frame in use for display, and W is a window displaying
684 REGION_BEG, REGION_END delimit the region, so it can be highlighted. */
687 compute_char_face (f
, w
, pos
, region_beg
, region_end
, endptr
)
691 int region_beg
, region_end
;
695 Lisp_Object prop
, position
;
698 Lisp_Object
*overlay_vec
;
699 struct sortvec
*sortvec
;
703 /* W must display the current buffer. We could write this function
704 to use the frame and buffer of W, but right now it doesn't. */
705 if (XBUFFER (w
->buffer
) != current_buffer
)
708 XSET (frame
, Lisp_Frame
, f
);
711 if (pos
< region_beg
&& region_beg
< endpos
)
714 XFASTINT (position
) = pos
;
715 prop
= Fget_text_property (position
, Qface
, w
->buffer
);
719 end
= Fnext_single_property_change (position
, Qface
, w
->buffer
);
728 /* First try with room for 40 overlays. */
730 overlay_vec
= (Lisp_Object
*) alloca (len
* sizeof (Lisp_Object
));
732 noverlays
= overlays_at (pos
, 0, &overlay_vec
, &len
, &next_overlay
);
734 /* If there are more than 40,
735 make enough space for all, and try again. */
739 overlay_vec
= (Lisp_Object
*) alloca (len
* sizeof (Lisp_Object
));
740 noverlays
= overlays_at (pos
, 0, &overlay_vec
, &len
, &next_overlay
);
743 if (next_overlay
< endpos
)
744 endpos
= next_overlay
;
749 /* Optimize the default case. */
750 if (noverlays
== 0 && NILP (prop
)
751 && !(pos
>= region_beg
&& pos
< region_end
))
754 compute_base_face (f
, &face
);
758 facecode
= face_name_id_number (f
, prop
);
759 if (facecode
>= 0 && facecode
< FRAME_N_FACES (f
)
760 && FRAME_FACES (f
) [facecode
] != 0)
761 merge_faces (FRAME_FACES (f
) [facecode
], &face
);
764 /* Put the valid and relevant overlays into sortvec. */
765 sortvec
= (struct sortvec
*) alloca (noverlays
* sizeof (struct sortvec
));
767 for (i
= 0, j
= 0; i
< noverlays
; i
++)
769 Lisp_Object overlay
= overlay_vec
[i
];
771 if (OVERLAY_VALID (overlay
)
772 && OVERLAY_POSITION (OVERLAY_START (overlay
)) > 0
773 && OVERLAY_POSITION (OVERLAY_END (overlay
)) > 0)
776 window
= Foverlay_get (overlay
, Qwindow
);
778 /* Also ignore overlays limited to one window
779 if it's not the window we are using. */
780 if (XTYPE (window
) != Lisp_Window
781 || XWINDOW (window
) == w
)
785 /* This overlay is good and counts:
786 put it in sortvec. */
787 sortvec
[j
].overlay
= overlay
;
788 sortvec
[j
].beg
= OVERLAY_POSITION (OVERLAY_START (overlay
));
789 sortvec
[j
].end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
790 tem
= Foverlay_get (overlay
, Qpriority
);
792 sortvec
[j
].priority
= XINT (tem
);
794 sortvec
[j
].priority
= 0;
801 /* Sort the overlays into the proper order: increasing priority. */
804 qsort (sortvec
, noverlays
, sizeof (struct sortvec
), sort_overlays
);
806 /* Now merge the overlay data in that order. */
807 for (i
= 0; i
< noverlays
; i
++)
809 prop
= Foverlay_get (sortvec
[i
].overlay
, Qface
);
815 facecode
= face_name_id_number (f
, prop
);
816 if (facecode
>= 0 && facecode
< FRAME_N_FACES (f
)
817 && FRAME_FACES (f
) [facecode
] != 0)
818 merge_faces (FRAME_FACES (f
) [facecode
], &face
);
820 oend
= OVERLAY_END (sortvec
[i
].overlay
);
821 oendpos
= OVERLAY_POSITION (oend
);
822 if (oendpos
< endpos
)
827 if (pos
>= region_beg
&& pos
< region_end
)
829 if (region_end
< endpos
)
831 if (region_face
>= 0 && region_face
< next_face_id
)
832 merge_faces (FRAME_FACES (f
) [region_face
], &face
);
837 return intern_frame_face (f
, &face
);
840 /* Return the face ID to use to display a special glyph which selects
841 FACE_CODE as the face ID, assuming that ordinarily the face would
842 be BASIC_FACE. F is the frame. */
844 compute_glyph_face (f
, face_code
)
850 compute_base_face (f
, &face
);
852 if (face_code
>= 0 && face_code
< FRAME_N_FACES (f
)
853 && FRAME_FACES (f
) [face_code
] != 0)
854 merge_faces (FRAME_FACES (f
) [face_code
], &face
);
856 return intern_frame_face (f
, &face
);
860 /* Recompute the GC's for the default and modeline faces.
861 We call this after changing frame parameters on which those GC's
864 recompute_basic_faces (f
)
867 /* If the frame's faces haven't been initialized yet, don't worry about
869 if (FRAME_N_FACES (f
) < 2)
874 if (FRAME_DEFAULT_FACE (f
)->gc
)
875 XFreeGC (x_current_display
, FRAME_DEFAULT_FACE (f
)->gc
);
876 build_face (f
, FRAME_DEFAULT_FACE (f
));
878 if (FRAME_MODE_LINE_FACE (f
)->gc
)
879 XFreeGC (x_current_display
, FRAME_MODE_LINE_FACE (f
)->gc
);
880 build_face (f
, FRAME_MODE_LINE_FACE (f
));
887 /* Lisp interface. */
889 DEFUN ("frame-face-alist", Fframe_face_alist
, Sframe_face_alist
, 1, 1, 0,
894 CHECK_FRAME (frame
, 0);
895 return XFRAME (frame
)->face_alist
;
898 DEFUN ("set-frame-face-alist", Fset_frame_face_alist
, Sset_frame_face_alist
,
901 Lisp_Object frame
, value
;
903 CHECK_FRAME (frame
, 0);
904 XFRAME (frame
)->face_alist
= value
;
909 DEFUN ("make-face-internal", Fmake_face_internal
, Smake_face_internal
, 1, 1, 0,
910 "Create face number FACE-ID on all frames.")
915 int id
= XINT (face_id
);
917 CHECK_NUMBER (face_id
, 0);
918 if (id
< 0 || id
>= next_face_id
)
919 error ("Face id out of range");
921 for (rest
= Vframe_list
; !NILP (rest
); rest
= XCONS (rest
)->cdr
)
923 struct frame
*f
= XFRAME (XCONS (rest
)->car
);
925 ensure_face_ready (f
, id
);
931 DEFUN ("set-face-attribute-internal", Fset_face_attribute_internal
,
932 Sset_face_attribute_internal
, 4, 4, 0, "")
933 (face_id
, attr_name
, attr_value
, frame
)
934 Lisp_Object face_id
, attr_name
, attr_value
, frame
;
941 CHECK_FRAME (frame
, 0);
942 CHECK_NUMBER (face_id
, 0);
943 CHECK_SYMBOL (attr_name
, 0);
947 if (id
< 0 || id
>= next_face_id
)
948 error ("Face id out of range");
953 ensure_face_ready (f
, id
);
954 face
= FRAME_FACES (f
) [XFASTINT (face_id
)];
956 if (EQ (attr_name
, intern ("font")))
958 XFontStruct
*font
= load_font (f
, attr_value
);
959 if (face
->font
!= f
->display
.x
->font
)
960 unload_font (f
, face
->font
);
963 else if (EQ (attr_name
, intern ("foreground")))
965 unsigned long new_color
= load_color (f
, attr_value
);
966 unload_color (f
, face
->foreground
);
967 face
->foreground
= new_color
;
969 else if (EQ (attr_name
, intern ("background")))
971 unsigned long new_color
= load_color (f
, attr_value
);
972 unload_color (f
, face
->background
);
973 face
->background
= new_color
;
976 else if (EQ (attr_name
, intern ("background-pixmap")))
978 unsigned int w
, h
, d
;
979 unsigned long new_pixmap
= load_pixmap (f
, attr_value
, &w
, &h
, &d
, 0);
980 unload_pixmap (f
, face
->stipple
);
981 if (NILP (attr_value
))
983 face
->stipple
= new_pixmap
;
986 /* face->pixmap_depth = d; */
989 else if (EQ (attr_name
, intern ("underline")))
991 int new = !NILP (attr_value
);
992 face
->underline
= new;
995 error ("unknown face attribute");
1000 if (FRAME_DEFAULT_FACE (f
)->gc
!= 0)
1001 XFreeGC (x_current_display
, FRAME_DEFAULT_FACE (f
)->gc
);
1002 build_face (f
, FRAME_DEFAULT_FACE (f
));
1009 if (FRAME_MODE_LINE_FACE (f
)->gc
!= 0)
1010 XFreeGC (x_current_display
, FRAME_MODE_LINE_FACE (f
)->gc
);
1011 build_face (f
, FRAME_MODE_LINE_FACE (f
));
1015 /* If we're modifying either of the frame's display faces, that
1016 means that we're changing the parameters of a fixed face code;
1017 since the color/font/whatever is changed but the face ID hasn't,
1018 redisplay won't know to redraw the affected sections. Give it a
1020 if (id
== 0 || id
== 1)
1021 SET_FRAME_GARBAGED (f
);
1023 /* Otherwise, it's enough to tell it to redisplay the text. */
1024 windows_or_buffers_changed
= 1;
1029 DEFUN ("internal-next-face-id", Finternal_next_face_id
, Sinternal_next_face_id
,
1033 return make_number (next_face_id
++);
1036 /* Return the face id for name NAME on frame FRAME.
1037 (It should be the same for all frames,
1038 but it's as easy to use the "right" frame to look it up
1039 as to use any other one.) */
1042 face_name_id_number (f
, name
)
1048 tem
= Fcdr (Fassq (name
, f
->face_alist
));
1051 CHECK_VECTOR (tem
, 0);
1052 tem
= XVECTOR (tem
)->contents
[2];
1053 CHECK_NUMBER (tem
, 0);
1057 /* Emacs initialization. */
1062 Qwindow
= intern ("window");
1063 staticpro (&Qwindow
);
1064 Qface
= intern ("face");
1066 Qpriority
= intern ("priority");
1067 staticpro (&Qpriority
);
1069 DEFVAR_INT ("region-face", ®ion_face
,
1070 "Face number to use to highlight the region\n\
1071 The region is highlighted with this face\n\
1072 when Transient Mark mode is enabled and the mark is active.");
1074 defsubr (&Sframe_face_alist
);
1075 defsubr (&Sset_frame_face_alist
);
1076 defsubr (&Smake_face_internal
);
1077 defsubr (&Sset_face_attribute_internal
);
1078 defsubr (&Sinternal_next_face_id
);
1081 #endif /* HAVE_X_WINDOWS */