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, on which it requires
38 time.h. On some such systems, Xos.h tries to redefine struct
39 timeval and struct timezone if USG is #defined while it is
41 #ifdef XOS_NEEDS_TIME_H
56 /* An explanation of the face data structures. */
58 /* ========================= Face Data Structures =========================
60 Let FACE-NAME be a symbol naming a face.
62 Let FACE-VECTOR be (assq FACE-NAME (frame-face-alist FRAME))
63 FACE-VECTOR is either nil, or a vector of the form
64 [face NAME ID FONT FOREGROUND BACKGROUND BACKGROUND-PIXMAP UNDERLINE-P]
66 face is the symbol `face',
67 NAME is the symbol with which this vector is associated (a backpointer),
68 ID is the face ID, an integer used internally by the C code to identify
70 FONT, FOREGROUND, and BACKGROUND are strings naming the fonts and colors
72 BACKGROUND-PIXMAP is the name of an x bitmap filename, which we don't
74 UNDERLINE-P is non-nil if the face should be underlined.
75 If any of these elements are nil, that parameter is considered
76 unspecified; parameters from faces specified by lower-priority
77 overlays or text properties, or the parameters of the frame itself,
78 can show through. (lisp/faces.el maintains these lists.)
80 (assq FACE-NAME global-face-data) returns a vector describing the
81 global parameters for that face.
83 Let PARAM-FACE be FRAME->display.x->param_faces[Faref (FACE-VECTOR, 2)].
84 PARAM_FACE is a struct face whose members are the Xlib analogues of
85 the parameters in FACE-VECTOR. If an element of FACE-VECTOR is
86 nil, then the corresponding member of PARAM_FACE is FACE_DEFAULT.
87 These faces are called "parameter faces", because they're the ones
88 lisp manipulates to control what gets displayed. Elements 0 and 1
89 of FRAME->display.x->param_faces are special - they describe the
90 default and mode line faces. None of the faces in param_faces have
91 GC's. (See src/dispextern.h for the definiton of struct face.
92 lisp/faces.el maintains the isomorphism between face_alist and
95 The functions compute_char_face and compute_glyph_face find and
96 combine the parameter faces associated with overlays and text
97 properties. The resulting faces are called "computed faces"; none
98 of their members are FACE_DEFAULT; they are completely specified.
99 They then call intern_compute_face to search
100 FRAME->display.x->computed_faces for a matching face, add one if
101 none is found, and return the index into
102 FRAME->display.x->computed_faces. FRAME's glyph matrices use these
103 indices to record the faces of the matrix characters, and the X
104 display hooks consult compute_faces to decide how to display these
105 characters. Elements 0 and 1 of computed_faces always describe the
106 default and mode-line faces.
108 Elements 0 and 1 of computed_faces have GC's; all the other faces
109 in computed_faces do not. The global array face_vector contains
110 faces with their GC's set. Given a computed_face, the function
111 intern_face finds (or adds) an element of face_vector with
112 equivalent parameters, and returns a pointer to that face, whose GC
113 can then be used for display.
117 Symbols naming faces must have associations on all frames; for any
118 FRAME, for all FACE-NAME, if (assq FACE-NAME (frame-face-alist
119 FRAME)) is non-nil, it must be non-nil for all frames.
121 Analogously, indices into param_faces must be valid on all frames;
122 if param_faces[i] is a non-zero face pointer on one frame, then it
123 must be filled in on all frames. Code assumes that face ID's can
124 be used on any frame.
128 Why do we keep param_faces and computed_faces separate?
129 computed_faces contains an element for every combination of facial
130 parameters we have ever displayed. indices into param_faces have
131 to be valid on all frames. If they were the same array, then that
132 array would grow very large on all frames, because any facial
133 combination displayed on any frame would need to be a valid entry
136 Since face_vector is just a cache --- there are no pointers into it
137 from the rest of the code, and everyone accesses it through
138 intern_face --- we could just free its GC's and throw the whole
139 thing away without breaking anything. This gives us a simple way
140 to garbage-collect old GC's nobody's using any more - we can just
141 purge face_vector, and then let subsequent calls to intern_face
142 refill it as needed. The function clear_face_vector performs this
145 We're often applying intern_face to faces in computed_faces -
146 for example, we do this while sending GLYPHs from a struct
147 frame_glyphs to X during redisplay. It would be nice to avoid
148 searching all of face_vector every time we intern a frame's face.
149 So, when intern_face finds a match for FACE in face_vector, it
150 stores the index of the match in FACE's cached_index member, and
151 checks there first next time. */
154 /* Definitions and declarations. */
156 /* A table of display faces. */
157 static struct face
**face_vector
;
158 /* The length in use of the table. */
160 /* The allocated length of the table. */
161 static int nfaces_allocated
;
163 /* The number of face-id's in use (same for all frames). */
166 /* The number of the face to use to indicate the region. */
169 /* This is what appears in a slot in a face to signify that the face
170 does not specify that display aspect. */
171 #define FACE_DEFAULT (~0)
173 Lisp_Object Qface
, Qwindow
, Qpriority
;
175 static void build_face ( /* FRAME_PTR, struct face * */ );
176 int face_name_id_number ( /* FRAME_PTR, Lisp_Object name */ );
178 struct face
*intern_face ( /* FRAME_PTR, struct face * */ );
179 static int new_computed_face ( /* FRAME_PTR, struct face * */ );
180 static int intern_computed_face ( /* FRAME_PTR, struct face * */ );
181 static void ensure_face_ready ( /* FRAME_PTR, int id */ );
182 void recompute_basic_faces ( /* FRAME_PTR f */ );
184 /* Allocating, copying, and comparing struct faces. */
186 /* Allocate a new face */
190 struct face
*result
= (struct face
*) xmalloc (sizeof (struct face
));
191 bzero (result
, sizeof (struct face
));
192 result
->font
= (XFontStruct
*) FACE_DEFAULT
;
193 result
->foreground
= FACE_DEFAULT
;
194 result
->background
= FACE_DEFAULT
;
195 result
->stipple
= FACE_DEFAULT
;
199 /* Make a new face that's a copy of an existing one. */
204 struct face
*result
= allocate_face ();
206 result
->font
= face
->font
;
207 result
->foreground
= face
->foreground
;
208 result
->background
= face
->background
;
209 result
->stipple
= face
->stipple
;
210 result
->underline
= face
->underline
;
216 face_eql (face1
, face2
)
217 struct face
*face1
, *face2
;
219 return ( face1
->font
== face2
->font
220 && face1
->foreground
== face2
->foreground
221 && face1
->background
== face2
->background
222 && face1
->stipple
== face2
->stipple
223 && face1
->underline
== face2
->underline
);
226 /* Interning faces in the `face_vector' cache, and clearing that cache. */
228 /* Return the unique display face corresponding to the user-level face FACE.
229 If there isn't one, make one, and find a slot in the face_vector to
232 get_cached_face (f
, face
)
239 /* Perhaps FACE->cached_index is valid; this could happen if FACE is
240 in a frame's face list. */
241 if (face
->cached_index
>= 0
242 && face
->cached_index
< nfaces
243 && face_eql (face_vector
[face
->cached_index
], face
))
244 return face_vector
[face
->cached_index
];
246 /* Look for an existing display face that does the job.
247 Also find an empty slot if any. */
248 for (i
= 0; i
< nfaces
; i
++)
250 if (face_eql (face_vector
[i
], face
))
251 return face_vector
[i
];
252 if (face_vector
[i
] == 0)
256 /* If no empty slots, make one. */
257 if (empty
< 0 && nfaces
== nfaces_allocated
)
259 int newsize
= nfaces
+ 20;
261 = (struct face
**) xrealloc (face_vector
,
262 newsize
* sizeof (struct face
*));
263 nfaces_allocated
= newsize
;
269 /* Put a new display face in the empty slot. */
270 result
= copy_face (face
);
271 face_vector
[empty
] = result
;
273 /* Make a graphics context for it. */
274 build_face (f
, result
);
279 /* Given a computed face, return an equivalent display face
280 (one which has a graphics context). */
283 intern_face (f
, face
)
287 /* If it's equivalent to the default face, use that. */
288 if (face_eql (face
, FRAME_DEFAULT_FACE (f
)))
290 if (!FRAME_DEFAULT_FACE (f
)->gc
)
291 build_face (f
, FRAME_DEFAULT_FACE (f
));
292 return FRAME_DEFAULT_FACE (f
);
295 /* If it's equivalent to the mode line face, use that. */
296 if (face_eql (face
, FRAME_MODE_LINE_FACE (f
)))
298 if (!FRAME_MODE_LINE_FACE (f
)->gc
)
299 build_face (f
, FRAME_MODE_LINE_FACE (f
));
300 return FRAME_MODE_LINE_FACE (f
);
303 /* If it's not one of the frame's default faces, it shouldn't have a GC. */
307 /* Get a specialized display face. */
308 return get_cached_face (f
, face
);
311 /* Clear out face_vector and start anew.
312 This should be done from time to time just to avoid
313 keeping too many graphics contexts in face_vector
314 that are no longer needed. */
320 Display
*dpy
= x_current_display
;
324 /* Free the display faces in the face_vector. */
325 for (i
= 0; i
< nfaces
; i
++)
327 struct face
*face
= face_vector
[i
];
329 XFreeGC (dpy
, face
->gc
);
337 /* Allocating and freeing X resources for display faces. */
339 /* Make a graphics context for face FACE, which is on frame F,
340 if that can be done. */
352 if (face
->foreground
!= FACE_DEFAULT
)
353 xgcv
.foreground
= face
->foreground
;
355 xgcv
.foreground
= f
->display
.x
->foreground_pixel
;
357 if (face
->background
!= FACE_DEFAULT
)
358 xgcv
.background
= face
->background
;
360 xgcv
.background
= f
->display
.x
->background_pixel
;
362 if (face
->font
&& (int) face
->font
!= FACE_DEFAULT
)
363 xgcv
.font
= face
->font
->fid
;
365 xgcv
.font
= f
->display
.x
->font
->fid
;
367 xgcv
.graphics_exposures
= 0;
369 mask
= GCForeground
| GCBackground
| GCFont
| GCGraphicsExposures
;
370 gc
= XCreateGC (x_current_display
, FRAME_X_WINDOW (f
),
374 if (face
->stipple
&& face
->stipple
!= FACE_DEFAULT
)
375 XSetStipple (x_current_display
, gc
, face
->stipple
);
383 /* Allocating, freeing, and duplicating fonts, colors, and pixmaps. */
393 return (XFontStruct
*) FACE_DEFAULT
;
395 CHECK_STRING (name
, 0);
397 font
= XLoadQueryFont (x_current_display
, (char *) XSTRING (name
)->data
);
401 Fsignal (Qerror
, Fcons (build_string ("undefined font"),
402 Fcons (name
, Qnil
)));
407 unload_font (f
, font
)
411 if (!font
|| font
== ((XFontStruct
*) FACE_DEFAULT
))
415 XFreeFont (x_current_display
, font
);
424 Display
*dpy
= x_current_display
;
432 cmap
= DefaultColormapOfScreen (DefaultScreenOfDisplay (x_current_display
));
434 CHECK_STRING (name
, 0);
436 result
= XParseColor (dpy
, cmap
, (char *) XSTRING (name
)->data
, &color
);
439 Fsignal (Qerror
, Fcons (build_string ("undefined color"),
440 Fcons (name
, Qnil
)));
442 result
= XAllocColor (dpy
, cmap
, &color
);
445 Fsignal (Qerror
, Fcons (build_string ("X server cannot allocate color"),
446 Fcons (name
, Qnil
)));
447 return (unsigned long) color
.pixel
;
451 unload_color (f
, pixel
)
455 /* Since faces get built by copying parameters from other faces, the
456 allocation counts for the colors get all screwed up. I don't see
457 any solution that will take less than 10 minutes, and it's better
458 to have a color leak than a crash, so I'm just dyking this out.
459 This isn't really a color leak, anyway - if we ask for it again,
460 we'll get the same pixel. */
463 Display
*dpy
= x_current_display
;
464 if (pixel
== FACE_DEFAULT
465 || pixel
== BLACK_PIX_DEFAULT
466 || pixel
== WHITE_PIX_DEFAULT
)
468 cmap
= DefaultColormapOfScreen (DefaultScreenOfDisplay (x_current_display
));
470 XFreeColors (dpy
, cmap
, &pixel
, 1, 0);
475 /* Managing parameter face arrays for frames. */
481 ensure_face_ready (f
, 0);
482 ensure_face_ready (f
, 1);
484 new_computed_face (f
, FRAME_PARAM_FACES (f
)[0]);
485 new_computed_face (f
, FRAME_PARAM_FACES (f
)[1]);
486 recompute_basic_faces (f
);
488 /* Find another X frame. */
490 Lisp_Object tail
, frame
, result
;
493 FOR_EACH_FRAME (tail
, frame
)
494 if (FRAME_X_P (XFRAME (frame
))
495 && XFRAME (frame
) != f
)
501 /* If we didn't find any X frames other than f, then we don't need
502 any faces other than 0 and 1, so we're okay. Otherwise, make
503 sure that all faces valid on the selected frame are also valid
504 on this new frame. */
508 int n_faces
= FRAME_N_PARAM_FACES (XFRAME (result
));
509 struct face
**faces
= FRAME_PARAM_FACES (XFRAME (result
));
511 for (i
= 2; i
< n_faces
; i
++)
513 ensure_face_ready (f
, i
);
519 /* Called from Fdelete_frame. */
524 Display
*dpy
= x_current_display
;
529 for (i
= 0; i
< FRAME_N_PARAM_FACES (f
); i
++)
531 struct face
*face
= FRAME_PARAM_FACES (f
) [i
];
535 XFreeGC (dpy
, face
->gc
);
536 unload_font (f
, face
->font
);
537 unload_color (f
, face
->foreground
);
538 unload_color (f
, face
->background
);
540 unload_pixmap (f
, face
->stipple
);
545 xfree (FRAME_PARAM_FACES (f
));
546 FRAME_PARAM_FACES (f
) = 0;
547 FRAME_N_PARAM_FACES (f
) = 0;
549 /* All faces in FRAME_COMPUTED_FACES use resources copied from
550 FRAME_PARAM_FACES; we can free them without fuss. */
551 xfree (FRAME_COMPUTED_FACES (f
));
552 FRAME_COMPUTED_FACES (f
) = 0;
553 FRAME_N_COMPUTED_FACES (f
) = 0;
558 /* Interning faces in a frame's face array. */
561 new_computed_face (f
, new_face
)
563 struct face
*new_face
;
565 int i
= FRAME_N_COMPUTED_FACES (f
);
567 if (i
>= FRAME_SIZE_COMPUTED_FACES (f
))
569 int new_size
= i
+ 32;
571 FRAME_COMPUTED_FACES (f
)
573 (FRAME_SIZE_COMPUTED_FACES (f
) == 0
574 ? xmalloc (new_size
* sizeof (struct face
*))
575 : xrealloc (FRAME_COMPUTED_FACES (f
),
576 new_size
* sizeof (struct face
*)));
577 FRAME_SIZE_COMPUTED_FACES (f
) = new_size
;
580 i
= FRAME_N_COMPUTED_FACES (f
)++;
581 FRAME_COMPUTED_FACES (f
)[i
] = copy_face (new_face
);
586 /* Find a match for NEW_FACE in a FRAME's computed face array, and add
587 it if we don't find one. */
589 intern_computed_face (f
, new_face
)
591 struct face
*new_face
;
593 int len
= FRAME_N_COMPUTED_FACES (f
);
596 /* Search for a computed face already on F equivalent to FACE. */
597 for (i
= 0; i
< len
; i
++)
599 if (! FRAME_COMPUTED_FACES (f
)[i
])
601 if (face_eql (new_face
, FRAME_COMPUTED_FACES (f
)[i
]))
605 /* We didn't find one; add a new one. */
606 return new_computed_face (f
, new_face
);
609 /* Make parameter face id ID valid on frame F. */
612 ensure_face_ready (f
, id
)
616 if (FRAME_N_PARAM_FACES (f
) <= id
)
620 if (!FRAME_N_PARAM_FACES (f
))
621 FRAME_PARAM_FACES (f
)
622 = (struct face
**) xmalloc (sizeof (struct face
*) * n
);
624 FRAME_PARAM_FACES (f
)
625 = (struct face
**) xrealloc (FRAME_PARAM_FACES (f
),
626 sizeof (struct face
*) * n
);
628 bzero (FRAME_PARAM_FACES (f
) + FRAME_N_PARAM_FACES (f
),
629 (n
- FRAME_N_PARAM_FACES (f
)) * sizeof (struct face
*));
630 FRAME_N_PARAM_FACES (f
) = n
;
633 if (FRAME_PARAM_FACES (f
) [id
] == 0)
634 FRAME_PARAM_FACES (f
) [id
] = allocate_face ();
637 /* Computing faces appropriate for a given piece of text in a buffer. */
639 /* Return non-zero if FONT1 and FONT2 have the same size bounding box.
640 We assume that they're both character-cell fonts. */
642 same_size_fonts (font1
, font2
)
643 XFontStruct
*font1
, *font2
;
645 XCharStruct
*bounds1
= &font1
->min_bounds
;
646 XCharStruct
*bounds2
= &font2
->min_bounds
;
648 return (bounds1
->width
== bounds2
->width
);
649 /* Checking the following caused bad results in some cases
650 when fonts that should be the same size
651 actually have very slightly different size.
652 It is possible that this reintroduces the bug whereby line positions
653 were not right. However, the right way to fix that is to change xterm.c
654 so that the vertical positions of lines
655 depend only on the height of the frame's font.
656 && bounds1->ascent == bounds2->ascent
657 && bounds1->descent == bounds2->descent); */
660 /* Modify face TO by copying from FROM all properties which have
661 nondefault settings. */
663 merge_faces (from
, to
)
664 struct face
*from
, *to
;
666 /* Only merge the font if it's the same size as the base font. */
667 if (from
->font
!= (XFontStruct
*) FACE_DEFAULT
668 && same_size_fonts (from
->font
, to
->font
))
669 to
->font
= from
->font
;
670 if (from
->foreground
!= FACE_DEFAULT
)
671 to
->foreground
= from
->foreground
;
672 if (from
->background
!= FACE_DEFAULT
)
673 to
->background
= from
->background
;
674 if (from
->stipple
!= FACE_DEFAULT
)
675 to
->stipple
= from
->stipple
;
677 to
->underline
= from
->underline
;
680 /* Set up the basic set of facial parameters, based on the frame's
681 data; all faces are deltas applied to this. */
683 compute_base_face (f
, face
)
687 struct x_display
*d
= f
->display
.x
;
690 face
->foreground
= d
->foreground_pixel
;
691 face
->background
= d
->background_pixel
;
692 face
->font
= d
->font
;
696 /* Avoid a face comparison by making this invalid. */
697 face
->cached_index
= -1;
709 sort_overlays (s1
, s2
)
710 struct sortvec
*s1
, *s2
;
712 if (s1
->priority
!= s2
->priority
)
713 return s1
->priority
- s2
->priority
;
714 if (s1
->beg
!= s2
->beg
)
715 return s1
->beg
- s2
->beg
;
716 if (s1
->end
!= s2
->end
)
717 return s2
->end
- s1
->end
;
721 /* Return the face ID associated with a buffer position POS.
722 Store into *ENDPTR the position at which a different face is needed.
723 This does not take account of glyphs that specify their own face codes.
724 F is the frame in use for display, and W is a window displaying
727 REGION_BEG, REGION_END delimit the region, so it can be highlighted.
729 LIMIT is a position not to scan beyond. That is to limit
730 the time this function can take. */
733 compute_char_face (f
, w
, pos
, region_beg
, region_end
, endptr
, limit
)
737 int region_beg
, region_end
;
742 Lisp_Object prop
, position
;
745 Lisp_Object
*overlay_vec
;
746 struct sortvec
*sortvec
;
750 /* W must display the current buffer. We could write this function
751 to use the frame and buffer of W, but right now it doesn't. */
752 if (XBUFFER (w
->buffer
) != current_buffer
)
755 XSET (frame
, Lisp_Frame
, f
);
758 if (pos
< region_beg
&& region_beg
< endpos
)
761 XFASTINT (position
) = pos
;
762 prop
= Fget_text_property (position
, Qface
, w
->buffer
);
764 Lisp_Object limit1
, end
;
766 XFASTINT (limit1
) = (limit
< endpos
? limit
: endpos
);
767 end
= Fnext_single_property_change (position
, Qface
, w
->buffer
, limit1
);
776 /* First try with room for 40 overlays. */
778 overlay_vec
= (Lisp_Object
*) alloca (len
* sizeof (Lisp_Object
));
780 noverlays
= overlays_at (pos
, 0, &overlay_vec
, &len
, &next_overlay
);
782 /* If there are more than 40,
783 make enough space for all, and try again. */
787 overlay_vec
= (Lisp_Object
*) alloca (len
* sizeof (Lisp_Object
));
788 noverlays
= overlays_at (pos
, 0, &overlay_vec
, &len
, &next_overlay
);
791 if (next_overlay
< endpos
)
792 endpos
= next_overlay
;
797 /* Optimize the default case. */
798 if (noverlays
== 0 && NILP (prop
)
799 && !(pos
>= region_beg
&& pos
< region_end
))
802 compute_base_face (f
, &face
);
806 facecode
= face_name_id_number (f
, prop
);
807 if (facecode
>= 0 && facecode
< FRAME_N_PARAM_FACES (f
)
808 && FRAME_PARAM_FACES (f
) [facecode
] != 0)
809 merge_faces (FRAME_PARAM_FACES (f
) [facecode
], &face
);
812 /* Put the valid and relevant overlays into sortvec. */
813 sortvec
= (struct sortvec
*) alloca (noverlays
* sizeof (struct sortvec
));
815 for (i
= 0, j
= 0; i
< noverlays
; i
++)
817 Lisp_Object overlay
= overlay_vec
[i
];
819 if (OVERLAY_VALID (overlay
)
820 && OVERLAY_POSITION (OVERLAY_START (overlay
)) > 0
821 && OVERLAY_POSITION (OVERLAY_END (overlay
)) > 0)
824 window
= Foverlay_get (overlay
, Qwindow
);
826 /* Also ignore overlays limited to one window
827 if it's not the window we are using. */
828 if (XTYPE (window
) != Lisp_Window
829 || XWINDOW (window
) == w
)
833 /* This overlay is good and counts:
834 put it in sortvec. */
835 sortvec
[j
].overlay
= overlay
;
836 sortvec
[j
].beg
= OVERLAY_POSITION (OVERLAY_START (overlay
));
837 sortvec
[j
].end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
838 tem
= Foverlay_get (overlay
, Qpriority
);
840 sortvec
[j
].priority
= XINT (tem
);
842 sortvec
[j
].priority
= 0;
849 /* Sort the overlays into the proper order: increasing priority. */
852 qsort (sortvec
, noverlays
, sizeof (struct sortvec
), sort_overlays
);
854 /* Now merge the overlay data in that order. */
855 for (i
= 0; i
< noverlays
; i
++)
857 prop
= Foverlay_get (sortvec
[i
].overlay
, Qface
);
863 facecode
= face_name_id_number (f
, prop
);
864 if (facecode
>= 0 && facecode
< FRAME_N_PARAM_FACES (f
)
865 && FRAME_PARAM_FACES (f
) [facecode
] != 0)
866 merge_faces (FRAME_PARAM_FACES (f
) [facecode
], &face
);
868 oend
= OVERLAY_END (sortvec
[i
].overlay
);
869 oendpos
= OVERLAY_POSITION (oend
);
870 if (oendpos
< endpos
)
875 if (pos
>= region_beg
&& pos
< region_end
)
877 if (region_end
< endpos
)
879 if (region_face
>= 0 && region_face
< next_face_id
)
880 merge_faces (FRAME_PARAM_FACES (f
) [region_face
], &face
);
885 return intern_computed_face (f
, &face
);
888 /* Return the face ID to use to display a special glyph which selects
889 FACE_CODE as the face ID, assuming that ordinarily the face would
890 be BASIC_FACE. F is the frame. */
892 compute_glyph_face (f
, face_code
)
898 compute_base_face (f
, &face
);
900 if (face_code
>= 0 && face_code
< FRAME_N_PARAM_FACES (f
)
901 && FRAME_PARAM_FACES (f
) [face_code
] != 0)
902 merge_faces (FRAME_PARAM_FACES (f
) [face_code
], &face
);
904 return intern_computed_face (f
, &face
);
908 /* Recompute the GC's for the default and modeline faces.
909 We call this after changing frame parameters on which those GC's
912 recompute_basic_faces (f
)
915 /* If the frame's faces haven't been initialized yet, don't worry about
917 if (FRAME_N_PARAM_FACES (f
) < 2)
922 if (FRAME_DEFAULT_FACE (f
)->gc
)
923 XFreeGC (x_current_display
, FRAME_DEFAULT_FACE (f
)->gc
);
924 if (FRAME_MODE_LINE_FACE (f
)->gc
)
925 XFreeGC (x_current_display
, FRAME_MODE_LINE_FACE (f
)->gc
);
927 compute_base_face (f
, FRAME_DEFAULT_FACE (f
));
928 compute_base_face (f
, FRAME_MODE_LINE_FACE (f
));
930 merge_faces (FRAME_DEFAULT_PARAM_FACE (f
), FRAME_DEFAULT_FACE (f
));
931 merge_faces (FRAME_MODE_LINE_PARAM_FACE (f
), FRAME_MODE_LINE_FACE (f
));
933 build_face (f
, FRAME_DEFAULT_FACE (f
));
934 build_face (f
, FRAME_MODE_LINE_FACE (f
));
941 /* Lisp interface. */
943 DEFUN ("frame-face-alist", Fframe_face_alist
, Sframe_face_alist
, 1, 1, 0,
948 CHECK_FRAME (frame
, 0);
949 return XFRAME (frame
)->face_alist
;
952 DEFUN ("set-frame-face-alist", Fset_frame_face_alist
, Sset_frame_face_alist
,
955 Lisp_Object frame
, value
;
957 CHECK_FRAME (frame
, 0);
958 XFRAME (frame
)->face_alist
= value
;
963 DEFUN ("make-face-internal", Fmake_face_internal
, Smake_face_internal
, 1, 1, 0,
964 "Create face number FACE-ID on all frames.")
969 int id
= XINT (face_id
);
971 CHECK_NUMBER (face_id
, 0);
972 if (id
< 0 || id
>= next_face_id
)
973 error ("Face id out of range");
975 for (rest
= Vframe_list
; !NILP (rest
); rest
= XCONS (rest
)->cdr
)
977 struct frame
*f
= XFRAME (XCONS (rest
)->car
);
979 ensure_face_ready (f
, id
);
985 DEFUN ("set-face-attribute-internal", Fset_face_attribute_internal
,
986 Sset_face_attribute_internal
, 4, 4, 0, "")
987 (face_id
, attr_name
, attr_value
, frame
)
988 Lisp_Object face_id
, attr_name
, attr_value
, frame
;
995 CHECK_FRAME (frame
, 0);
996 CHECK_NUMBER (face_id
, 0);
997 CHECK_SYMBOL (attr_name
, 0);
1000 id
= XINT (face_id
);
1001 if (id
< 0 || id
>= next_face_id
)
1002 error ("Face id out of range");
1004 if (! FRAME_X_P (f
))
1007 ensure_face_ready (f
, id
);
1008 face
= FRAME_PARAM_FACES (f
) [XFASTINT (face_id
)];
1010 if (EQ (attr_name
, intern ("font")))
1012 XFontStruct
*font
= load_font (f
, attr_value
);
1013 if (face
->font
!= f
->display
.x
->font
)
1014 unload_font (f
, face
->font
);
1017 else if (EQ (attr_name
, intern ("foreground")))
1019 unsigned long new_color
= load_color (f
, attr_value
);
1020 unload_color (f
, face
->foreground
);
1021 face
->foreground
= new_color
;
1023 else if (EQ (attr_name
, intern ("background")))
1025 unsigned long new_color
= load_color (f
, attr_value
);
1026 unload_color (f
, face
->background
);
1027 face
->background
= new_color
;
1030 else if (EQ (attr_name
, intern ("background-pixmap")))
1032 unsigned int w
, h
, d
;
1033 unsigned long new_pixmap
= load_pixmap (f
, attr_value
, &w
, &h
, &d
, 0);
1034 unload_pixmap (f
, face
->stipple
);
1035 if (NILP (attr_value
))
1037 face
->stipple
= new_pixmap
;
1040 /* face->pixmap_depth = d; */
1043 else if (EQ (attr_name
, intern ("underline")))
1045 int new = !NILP (attr_value
);
1046 face
->underline
= new;
1049 error ("unknown face attribute");
1051 if (id
== 0 || id
== 1)
1052 recompute_basic_faces (f
);
1054 /* If we're modifying either of the frame's display faces, that
1055 means that we're changing the parameters of a fixed face code;
1056 since the color/font/whatever is changed but the face ID hasn't,
1057 redisplay won't know to redraw the affected sections. Give it a
1059 if (id
== 0 || id
== 1)
1060 SET_FRAME_GARBAGED (f
);
1062 /* Otherwise, it's enough to tell it to redisplay the text. */
1063 windows_or_buffers_changed
= 1;
1068 DEFUN ("internal-next-face-id", Finternal_next_face_id
, Sinternal_next_face_id
,
1072 return make_number (next_face_id
++);
1075 /* Return the face id for name NAME on frame FRAME.
1076 (It should be the same for all frames,
1077 but it's as easy to use the "right" frame to look it up
1078 as to use any other one.) */
1081 face_name_id_number (f
, name
)
1087 tem
= Fcdr (assq_no_quit (name
, f
->face_alist
));
1090 CHECK_VECTOR (tem
, 0);
1091 tem
= XVECTOR (tem
)->contents
[2];
1092 CHECK_NUMBER (tem
, 0);
1096 /* Emacs initialization. */
1101 Qwindow
= intern ("window");
1102 staticpro (&Qwindow
);
1103 Qface
= intern ("face");
1105 Qpriority
= intern ("priority");
1106 staticpro (&Qpriority
);
1108 DEFVAR_INT ("region-face", ®ion_face
,
1109 "Face number to use to highlight the region\n\
1110 The region is highlighted with this face\n\
1111 when Transient Mark mode is enabled and the mark is active.");
1113 defsubr (&Sframe_face_alist
);
1114 defsubr (&Sset_frame_face_alist
);
1115 defsubr (&Smake_face_internal
);
1116 defsubr (&Sset_face_attribute_internal
);
1117 defsubr (&Sinternal_next_face_id
);
1120 #endif /* HAVE_X_WINDOWS */