comparison src/objects-x.c @ 185:3d6bfa290dbd r20-3b19

Import from CVS: tag r20-3b19
author cvs
date Mon, 13 Aug 2007 09:55:28 +0200
parents 538048ae2ab8
children 262b8bb4a523
comparison
equal deleted inserted replaced
184:bcd2674570bf 185:3d6bfa290dbd
65 int nearest; 65 int nearest;
66 long nearest_delta, trial_delta; 66 long nearest_delta, trial_delta;
67 int x; 67 int x;
68 68
69 no_cells = XDisplayCells (display, XDefaultScreen (display)); 69 no_cells = XDisplayCells (display, XDefaultScreen (display));
70 cells = (XColor *) alloca (sizeof (XColor) * no_cells); 70 cells = alloca_array (XColor, no_cells);
71 71
72 for (x = 0; x < no_cells; x++) 72 for (x = 0; x < no_cells; x++)
73 cells[x].pixel = x; 73 cells[x].pixel = x;
74 74
75 XQueryColors (display, screen_colormap, cells, no_cells); 75 XQueryColors (display, screen_colormap, cells, no_cells);
114 { 114 {
115 Display *dpy; 115 Display *dpy;
116 Screen *xs; 116 Screen *xs;
117 Colormap cmap; 117 Colormap cmap;
118 int result; 118 int result;
119 119
120 dpy = DEVICE_X_DISPLAY (d); 120 dpy = DEVICE_X_DISPLAY (d);
121 xs = DefaultScreenOfDisplay (dpy); 121 xs = DefaultScreenOfDisplay (dpy);
122 cmap = DefaultColormapOfScreen (xs); 122 cmap = DefaultColormapOfScreen (xs);
123 123
124 memset (color, 0, sizeof (*color)); 124 memset (color, 0, sizeof (*color));
125 { 125 {
126 CONST Extbyte *extname; 126 CONST Extbyte *extname;
127 Extcount extnamelen; 127 Extcount extnamelen;
128 128
161 if (!result) 161 if (!result)
162 return 0; 162 return 0;
163 163
164 /* Don't allocate the data until we're sure that we will succeed, 164 /* Don't allocate the data until we're sure that we will succeed,
165 or the finalize method may get fucked. */ 165 or the finalize method may get fucked. */
166 c->data = malloc_type (struct x_color_instance_data); 166 c->data = xnew (struct x_color_instance_data);
167 COLOR_INSTANCE_X_COLOR (c) = color; 167 COLOR_INSTANCE_X_COLOR (c) = color;
168 return 1; 168 return 1;
169 } 169 }
170 170
171 static void 171 static void
186 if (c->data) 186 if (c->data)
187 { 187 {
188 if (DEVICE_LIVE_P (XDEVICE (c->device))) 188 if (DEVICE_LIVE_P (XDEVICE (c->device)))
189 { 189 {
190 Display *dpy = DEVICE_X_DISPLAY (XDEVICE (c->device)); 190 Display *dpy = DEVICE_X_DISPLAY (XDEVICE (c->device));
191 191
192 XFreeColors (dpy, 192 XFreeColors (dpy,
193 DefaultColormapOfScreen (DefaultScreenOfDisplay (dpy)), 193 DefaultColormapOfScreen (DefaultScreenOfDisplay (dpy)),
194 &COLOR_INSTANCE_X_COLOR (c).pixel, 1, 0); 194 &COLOR_INSTANCE_X_COLOR (c).pixel, 1, 0);
195 } 195 }
196 xfree (c->data); 196 xfree (c->data);
224 224
225 static Lisp_Object 225 static Lisp_Object
226 x_color_instance_rgb_components (struct Lisp_Color_Instance *c) 226 x_color_instance_rgb_components (struct Lisp_Color_Instance *c)
227 { 227 {
228 XColor color = COLOR_INSTANCE_X_COLOR (c); 228 XColor color = COLOR_INSTANCE_X_COLOR (c);
229 return (list3 (make_int (color.red), 229 return (list3 (make_int (color.red),
230 make_int (color.green), 230 make_int (color.green),
231 make_int (color.blue))); 231 make_int (color.blue)));
232 } 232 }
233 233
234 static int 234 static int
235 x_valid_color_name_p (struct device *d, Lisp_Object color) 235 x_valid_color_name_p (struct device *d, Lisp_Object color)
236 { 236 {
237 XColor c; 237 XColor c;
238 Display *dpy = DEVICE_X_DISPLAY (d); 238 Display *dpy = DEVICE_X_DISPLAY (d);
239 CONST char *extname; 239 CONST char *extname;
240 240
241 GET_C_STRING_CTEXT_DATA_ALLOCA (color, extname); 241 GET_C_STRING_CTEXT_DATA_ALLOCA (color, extname);
242 242
243 return XParseColor (dpy, 243 return XParseColor (dpy,
244 DefaultColormapOfScreen (DefaultScreenOfDisplay (dpy)), 244 DefaultColormapOfScreen (DefaultScreenOfDisplay (dpy)),
245 extname, &c); 245 extname, &c);
255 Lisp_Object device, Error_behavior errb) 255 Lisp_Object device, Error_behavior errb)
256 { 256 {
257 Display *dpy; 257 Display *dpy;
258 XFontStruct *xf; 258 XFontStruct *xf;
259 CONST char *extname; 259 CONST char *extname;
260 260
261 dpy = DEVICE_X_DISPLAY (XDEVICE (device)); 261 dpy = DEVICE_X_DISPLAY (XDEVICE (device));
262 GET_C_STRING_CTEXT_DATA_ALLOCA (f->name, extname); 262 GET_C_STRING_CTEXT_DATA_ALLOCA (f->name, extname);
263 xf = XLoadQueryFont (dpy, extname); 263 xf = XLoadQueryFont (dpy, extname);
264 264
265 if (!xf) 265 if (!xf)
266 { 266 {
267 maybe_signal_simple_error ("couldn't load font", f->name, 267 maybe_signal_simple_error ("couldn't load font", f->name,
268 Qfont, errb); 268 Qfont, errb);
269 return 0; 269 return 0;
270 } 270 }
271 271
272 if (!xf->max_bounds.width) 272 if (!xf->max_bounds.width)
273 { 273 {
274 /* yes, this has been known to happen. */ 274 /* yes, this has been known to happen. */
275 XFreeFont (dpy, xf); 275 XFreeFont (dpy, xf);
276 maybe_signal_simple_error ("X font is too small", f->name, 276 maybe_signal_simple_error ("X font is too small", f->name,
277 Qfont, errb); 277 Qfont, errb);
278 return 0; 278 return 0;
279 } 279 }
280 280
281 /* Don't allocate the data until we're sure that we will succeed, 281 /* Don't allocate the data until we're sure that we will succeed,
282 or the finalize method may get fucked. */ 282 or the finalize method may get fucked. */
283 f->data = malloc_type (struct x_font_instance_data); 283 f->data = xnew (struct x_font_instance_data);
284 FONT_INSTANCE_X_TRUENAME (f) = Qnil; 284 FONT_INSTANCE_X_TRUENAME (f) = Qnil;
285 FONT_INSTANCE_X_FONT (f) = xf; 285 FONT_INSTANCE_X_FONT (f) = xf;
286 f->ascent = xf->ascent; 286 f->ascent = xf->ascent;
287 f->descent = xf->descent; 287 f->descent = xf->descent;
288 f->height = xf->ascent + xf->descent; 288 f->height = xf->ascent + xf->descent;
308 xf->min_char_or_byte2 + 1) + 308 xf->min_char_or_byte2 + 1) +
309 (byte2 - xf->min_char_or_byte2)].width; 309 (byte2 - xf->min_char_or_byte2)].width;
310 } 310 }
311 else 311 else
312 f->width = xf->max_bounds.width; 312 f->width = xf->max_bounds.width;
313 313
314 /* Some fonts have a default char whose width is 0. This is no good. 314 /* Some fonts have a default char whose width is 0. This is no good.
315 If that's the case, first try 'n' as the default char, and if n has 315 If that's the case, first try 'n' as the default char, and if n has
316 0 width too (unlikely) then just use the max width. */ 316 0 width too (unlikely) then just use the max width. */
317 if (f->width == 0) 317 if (f->width == 0)
318 { 318 {
361 } 361 }
362 362
363 static void 363 static void
364 x_finalize_font_instance (struct Lisp_Font_Instance *f) 364 x_finalize_font_instance (struct Lisp_Font_Instance *f)
365 { 365 {
366 366
367 if (f->data) 367 if (f->data)
368 { 368 {
369 if (DEVICE_LIVE_P (XDEVICE (f->device))) 369 if (DEVICE_LIVE_P (XDEVICE (f->device)))
370 { 370 {
371 Display *dpy = DEVICE_X_DISPLAY (XDEVICE (f->device)); 371 Display *dpy = DEVICE_X_DISPLAY (XDEVICE (f->device));
450 which is crazy, because that font doesn't even match that pattern! It is 450 which is crazy, because that font doesn't even match that pattern! It is
451 also not included in the output produced by `xlsfonts' with that pattern. 451 also not included in the output produced by `xlsfonts' with that pattern.
452 452
453 So this is yet another example of XListFonts() and XOpenFont() using 453 So this is yet another example of XListFonts() and XOpenFont() using
454 completely different algorithms. This, however, is a goofier example of 454 completely different algorithms. This, however, is a goofier example of
455 this bug, because in this case, it's not just the search order that is 455 this bug, because in this case, it's not just the search order that is
456 different -- the sets don't even intersect. 456 different -- the sets don't even intersect.
457 457
458 If anyone has any better ideas how to do this, or any insights on what it is 458 If anyone has any better ideas how to do this, or any insights on what it is
459 that the various servers are actually doing, please let me know! -- jwz. */ 459 that the various servers are actually doing, please let me know! -- jwz. */
460 460
548 548
549 FAIL: 549 FAIL:
550 if (ok) 550 if (ok)
551 { 551 {
552 int L = strlen (composed_name) + 1; 552 int L = strlen (composed_name) + 1;
553 result = xmalloc (L); 553 result = (char *) xmalloc (L);
554 strncpy (result, composed_name, L); 554 strncpy (result, composed_name, L);
555 } 555 }
556 else 556 else
557 result = 0; 557 result = 0;
558 558
606 x_font_truename (Display *dpy, char *name, XFontStruct *font) 606 x_font_truename (Display *dpy, char *name, XFontStruct *font)
607 { 607 {
608 char *truename_FONT = 0; 608 char *truename_FONT = 0;
609 char *truename_random = 0; 609 char *truename_random = 0;
610 char *truename = 0; 610 char *truename = 0;
611 611
612 /* The search order is: 612 /* The search order is:
613 - if FONT property exists, and is a valid name, return it. 613 - if FONT property exists, and is a valid name, return it.
614 - if the other props exist, and add up to a valid name, return it. 614 - if the other props exist, and add up to a valid name, return it.
615 - if we find a matching name with XListFonts, return it. 615 - if we find a matching name with XListFonts, return it.
616 - if FONT property exists, return it regardless. 616 - if FONT property exists, return it regardless.
694 struct device *d = XDEVICE (f->device); 694 struct device *d = XDEVICE (f->device);
695 int i; 695 int i;
696 Lisp_Object result = Qnil; 696 Lisp_Object result = Qnil;
697 XFontProp *props; 697 XFontProp *props;
698 Display *dpy; 698 Display *dpy;
699 699
700 dpy = DEVICE_X_DISPLAY (d); 700 dpy = DEVICE_X_DISPLAY (d);
701 props = FONT_INSTANCE_X_FONT (f)->properties; 701 props = FONT_INSTANCE_X_FONT (f)->properties;
702 for (i = FONT_INSTANCE_X_FONT (f)->n_properties - 1; i >= 0; i--) 702 for (i = FONT_INSTANCE_X_FONT (f)->n_properties - 1; i >= 0; i--)
703 { 703 {
704 char *name_str = 0; 704 char *name_str = 0;
748 int count = 0; 748 int count = 0;
749 Lisp_Object result = Qnil; 749 Lisp_Object result = Qnil;
750 CONST char *patternext; 750 CONST char *patternext;
751 751
752 GET_C_STRING_BINARY_DATA_ALLOCA (pattern, patternext); 752 GET_C_STRING_BINARY_DATA_ALLOCA (pattern, patternext);
753 753
754 names = XListFonts (DEVICE_X_DISPLAY (XDEVICE (device)), 754 names = XListFonts (DEVICE_X_DISPLAY (XDEVICE (device)),
755 patternext, MAX_FONT_COUNT, &count); 755 patternext, MAX_FONT_COUNT, &count);
756 while (count--) 756 while (count--)
757 result = Fcons (build_ext_string (names [count], FORMAT_BINARY), result); 757 result = Fcons (build_ext_string (names [count], FORMAT_BINARY), result);
758 if (names) 758 if (names)
777 if (EQ (charset, Vcharset_ascii)) 777 if (EQ (charset, Vcharset_ascii))
778 { 778 {
779 CONST Bufbyte *the_nonreloc = nonreloc; 779 CONST Bufbyte *the_nonreloc = nonreloc;
780 int i; 780 int i;
781 Bytecount the_length = length; 781 Bytecount the_length = length;
782 782
783 if (!the_nonreloc) 783 if (!the_nonreloc)
784 the_nonreloc = XSTRING_DATA (reloc); 784 the_nonreloc = XSTRING_DATA (reloc);
785 fixup_internal_substring (nonreloc, reloc, offset, &the_length); 785 fixup_internal_substring (nonreloc, reloc, offset, &the_length);
786 the_nonreloc += offset; 786 the_nonreloc += offset;
787 if (!memchr (the_nonreloc, '*', the_length)) 787 if (!memchr (the_nonreloc, '*', the_length))
788 { 788 {
789 for (i = 0;; i++) 789 for (i = 0;; i++)
790 { 790 {
791 CONST Bufbyte *new_nonreloc = 791 CONST Bufbyte *new_nonreloc = (CONST Bufbyte *)
792 memchr (the_nonreloc, '-', the_length); 792 memchr (the_nonreloc, '-', the_length);
793 if (!new_nonreloc) 793 if (!new_nonreloc)
794 break; 794 break;
795 new_nonreloc++; 795 new_nonreloc++;
796 the_length -= new_nonreloc - the_nonreloc; 796 the_length -= new_nonreloc - the_nonreloc;
797 the_nonreloc = new_nonreloc; 797 the_nonreloc = new_nonreloc;
798 } 798 }
799 799
800 /* If it has less than 5 dashes, it's a short font. 800 /* If it has less than 5 dashes, it's a short font.
801 Of course, long fonts always have 14 dashes or so, but short 801 Of course, long fonts always have 14 dashes or so, but short
802 fonts never have more than 1 or 2 dashes, so this is some 802 fonts never have more than 1 or 2 dashes, so this is some
803 sort of reasonable heuristic. */ 803 sort of reasonable heuristic. */
804 if (i < 5) 804 if (i < 5)
805 return 1; 805 return 1;
806 } 806 }
807 } 807 }
808 808
809 return (fast_string_match (XCHARSET_REGISTRY (charset), 809 return (fast_string_match (XCHARSET_REGISTRY (charset),
810 nonreloc, reloc, offset, length, 1, 810 nonreloc, reloc, offset, length, 1,
811 ERROR_ME, 0) >= 0); 811 ERROR_ME, 0) >= 0);
812 } 812 }
813 813
822 Lisp_Object result = Qnil; 822 Lisp_Object result = Qnil;
823 CONST char *patternext; 823 CONST char *patternext;
824 int i; 824 int i;
825 825
826 GET_C_STRING_BINARY_DATA_ALLOCA (font, patternext); 826 GET_C_STRING_BINARY_DATA_ALLOCA (font, patternext);
827 827
828 names = XListFonts (DEVICE_X_DISPLAY (XDEVICE (device)), 828 names = XListFonts (DEVICE_X_DISPLAY (XDEVICE (device)),
829 patternext, MAX_FONT_COUNT, &count); 829 patternext, MAX_FONT_COUNT, &count);
830 for (i = 0; i < count; i ++) 830 for (i = 0; i < count; i ++)
831 { 831 {
832 CONST char *intname; 832 CONST char *intname;
910 910
911 void 911 void
912 Xatoms_of_objects_x (struct device *d) 912 Xatoms_of_objects_x (struct device *d)
913 { 913 {
914 Display *D = DEVICE_X_DISPLAY (d); 914 Display *D = DEVICE_X_DISPLAY (d);
915 915
916 DEVICE_XATOM_FOUNDRY (d) = XInternAtom (D, "FOUNDRY", False); 916 DEVICE_XATOM_FOUNDRY (d) = XInternAtom (D, "FOUNDRY", False);
917 DEVICE_XATOM_FAMILY_NAME (d) = XInternAtom (D, "FAMILY_NAME", False); 917 DEVICE_XATOM_FAMILY_NAME (d) = XInternAtom (D, "FAMILY_NAME", False);
918 DEVICE_XATOM_WEIGHT_NAME (d) = XInternAtom (D, "WEIGHT_NAME", False); 918 DEVICE_XATOM_WEIGHT_NAME (d) = XInternAtom (D, "WEIGHT_NAME", False);
919 DEVICE_XATOM_SLANT (d) = XInternAtom (D, "SLANT", False); 919 DEVICE_XATOM_SLANT (d) = XInternAtom (D, "SLANT", False);
920 DEVICE_XATOM_SETWIDTH_NAME (d) = XInternAtom (D, "SETWIDTH_NAME", False); 920 DEVICE_XATOM_SETWIDTH_NAME (d) = XInternAtom (D, "SETWIDTH_NAME", False);