Mercurial > hg > xemacs-beta
comparison src/device-x.c @ 394:7d59cb494b73 r21-2-12
Import from CVS: tag r21-2-12
author | cvs |
---|---|
date | Mon, 13 Aug 2007 11:11:37 +0200 |
parents | aabb7f5b1c81 |
children | 74fd4e045ea6 |
comparison
equal
deleted
inserted
replaced
393:2e030b8965b1 | 394:7d59cb494b73 |
---|---|
315 Bytecount len = XSTRING_LENGTH (str); | 315 Bytecount len = XSTRING_LENGTH (str); |
316 Dynarr_add_many (cda, (char *) XSTRING_DATA (str), len); | 316 Dynarr_add_many (cda, (char *) XSTRING_DATA (str), len); |
317 validify_resource_component (Dynarr_atp (cda, Dynarr_length (cda) - len), len); | 317 validify_resource_component (Dynarr_atp (cda, Dynarr_length (cda) - len), len); |
318 } | 318 } |
319 | 319 |
320 #if 0 | |
321 /* compare visual info for qsorting */ | |
322 static int | |
323 x_comp_visual_info (const void *elem1, const void *elem2) | |
324 { | |
325 XVisualInfo *left, *right; | |
326 | |
327 left = (XVisualInfo *)elem1; | |
328 right = (XVisualInfo *)elem2; | |
329 | |
330 if ( left == NULL ) | |
331 return -1; | |
332 if ( right == NULL ) | |
333 return 1; | |
334 | |
335 if ( left->depth > right->depth ) { | |
336 return 1; | |
337 } | |
338 else if ( left->depth == right->depth ) { | |
339 if ( left->colormap_size > right->colormap_size ) | |
340 return 1; | |
341 if ( left->class > right->class ) | |
342 return 1; | |
343 else if ( left->class < right->class ) | |
344 return -1; | |
345 else | |
346 return 0; | |
347 } | |
348 else { | |
349 return -1; | |
350 } | |
351 | |
352 } | |
353 #endif /* if 0 */ | |
354 | |
355 #define XXX_IMAGE_LIBRARY_IS_SOMEWHAT_BROKEN | |
356 static Visual * | |
357 x_try_best_visual_class (Screen *screen, int scrnum, int visual_class) | |
358 { | |
359 Display *dpy = DisplayOfScreen (screen); | |
360 XVisualInfo vi_in; | |
361 XVisualInfo *vi_out = NULL; | |
362 int out_count; | |
363 | |
364 vi_in.class = visual_class; | |
365 vi_in.screen = scrnum; | |
366 vi_out = XGetVisualInfo (dpy, (VisualClassMask | VisualScreenMask), | |
367 &vi_in, &out_count); | |
368 if ( vi_out ) | |
369 { | |
370 int i, best; | |
371 Visual *visual; | |
372 for (i = 0, best = 0; i < out_count; i++) | |
373 /* It's better if it's deeper, or if it's the same depth with | |
374 more cells (does that ever happen? Well, it could...) | |
375 NOTE: don't allow pseudo color to get larger than 8! */ | |
376 if (((vi_out [i].depth > vi_out [best].depth) || | |
377 ((vi_out [i].depth == vi_out [best].depth) && | |
378 (vi_out [i].colormap_size > vi_out [best].colormap_size))) | |
379 #ifdef XXX_IMAGE_LIBRARY_IS_SOMEWHAT_BROKEN | |
380 /* For now, the image library doesn't like PseudoColor visuals | |
381 of depths other than 1 or 8. Depths greater than 8 only occur | |
382 on machines which have TrueColor anyway, so probably we'll end | |
383 up using that (it is the one that `Best' would pick) but if a | |
384 PseudoColor visual is explicitly specified, pick the 8 bit one. | |
385 */ | |
386 && (visual_class != PseudoColor || | |
387 vi_out [i].depth == 1 || | |
388 vi_out [i].depth == 8) | |
389 #endif | |
390 | |
391 /* SGI has 30-bit deep visuals. Ignore them. | |
392 (We only have 24-bit data anyway.) | |
393 */ | |
394 && (vi_out [i].depth <= 24) | |
395 ) | |
396 best = i; | |
397 visual = vi_out[best].visual; | |
398 XFree ((char *) vi_out); | |
399 return visual; | |
400 } | |
401 else | |
402 return 0; | |
403 } | |
404 | |
405 static int | |
406 x_get_visual_depth (Display *dpy, Visual *visual) | |
407 { | |
408 XVisualInfo vi_in; | |
409 XVisualInfo *vi_out; | |
410 int out_count, d; | |
411 | |
412 vi_in.visualid = XVisualIDFromVisual (visual); | |
413 vi_out = XGetVisualInfo (dpy, /*VisualScreenMask|*/VisualIDMask, | |
414 &vi_in, &out_count); | |
415 if (! vi_out) abort (); | |
416 d = vi_out [0].depth; | |
417 XFree ((char *) vi_out); | |
418 return d; | |
419 } | |
420 | |
421 static Visual * | |
422 x_try_best_visual (Display *dpy, int scrnum) | |
423 { | |
424 Visual *visual = NULL; | |
425 Screen *screen = ScreenOfDisplay (dpy, scrnum); | |
426 if ((visual = x_try_best_visual_class (screen, scrnum, TrueColor)) | |
427 && x_get_visual_depth (dpy, visual) >= 16 ) | |
428 return visual; | |
429 if ((visual = x_try_best_visual_class (screen, scrnum, PseudoColor))) | |
430 return visual; | |
431 if ((visual = x_try_best_visual_class (screen, scrnum, TrueColor))) | |
432 return visual; | |
433 #ifdef DIRECTCOLOR_WORKS | |
434 if ((visual = x_try_best_visual_class (screen, scrnum, DirectColor))) | |
435 return visual; | |
436 #endif | |
437 | |
438 visual = DefaultVisualOfScreen (screen); | |
439 if ( x_get_visual_depth (dpy, visual) >= 8 ) | |
440 return visual; | |
441 | |
442 if ((visual = x_try_best_visual_class (screen, scrnum, StaticGray))) | |
443 return visual; | |
444 if ((visual = x_try_best_visual_class (screen, scrnum, GrayScale))) | |
445 return visual; | |
446 return DefaultVisualOfScreen (screen); | |
447 } | |
448 | |
449 | |
320 static void | 450 static void |
321 x_init_device (struct device *d, Lisp_Object props) | 451 x_init_device (struct device *d, Lisp_Object props) |
322 { | 452 { |
323 Lisp_Object display; | 453 Lisp_Object display; |
324 Lisp_Object device; | 454 Lisp_Object device; |
331 CONST char *disp_name; | 461 CONST char *disp_name; |
332 Visual *visual = NULL; | 462 Visual *visual = NULL; |
333 int depth = 8; /* shut up the compiler */ | 463 int depth = 8; /* shut up the compiler */ |
334 Colormap cmap; | 464 Colormap cmap; |
335 int screen; | 465 int screen; |
466 /* */ | |
467 int best_visual_found = 0; | |
336 | 468 |
337 XSETDEVICE (device, d); | 469 XSETDEVICE (device, d); |
338 display = DEVICE_CONNECTION (d); | 470 display = DEVICE_CONNECTION (d); |
339 | 471 |
340 allocate_x_device_struct (d); | 472 allocate_x_device_struct (d); |
345 | 477 |
346 /* | 478 /* |
347 * Break apart the old XtOpenDisplay call into XOpenDisplay and | 479 * Break apart the old XtOpenDisplay call into XOpenDisplay and |
348 * XtDisplayInitialize so we can figure out whether there | 480 * XtDisplayInitialize so we can figure out whether there |
349 * are any XEmacs resources in the resource database before | 481 * are any XEmacs resources in the resource database before |
350 * we intitialize Xt. This is so we can automagically support | 482 * we initialize Xt. This is so we can automagically support |
351 * both `Emacs' and `XEmacs' application classes. | 483 * both `Emacs' and `XEmacs' application classes. |
352 */ | 484 */ |
353 slow_down_interrupts (); | 485 slow_down_interrupts (); |
354 /* May not be needed but XtOpenDisplay could not deal with signals here. */ | 486 /* May not be needed but XtOpenDisplay could not deal with signals here. */ |
355 dpy = DEVICE_X_DISPLAY (d) = XOpenDisplay (disp_name); | 487 dpy = DEVICE_X_DISPLAY (d) = XOpenDisplay (disp_name); |
485 stderr_out( "Invalid Visual specification in %s... ignoring.\n", str); | 617 stderr_out( "Invalid Visual specification in %s... ignoring.\n", str); |
486 } | 618 } |
487 } | 619 } |
488 if (visual == NULL) | 620 if (visual == NULL) |
489 { | 621 { |
490 visual = DefaultVisual (dpy, screen); | 622 /* |
491 depth = DefaultDepth (dpy, screen); | 623 visual = DefaultVisual(dpy, screen); |
624 depth = DefaultDepth(dpy, screen); | |
625 */ | |
626 visual = x_try_best_visual (dpy, screen); | |
627 depth = x_get_visual_depth (dpy, visual); | |
628 best_visual_found = (visual != DefaultVisual (dpy, screen)); | |
492 } | 629 } |
493 | 630 |
494 /* If we've got the same visual as the default and it's PseudoColor, | 631 /* If we've got the same visual as the default and it's PseudoColor, |
495 check to see if the user specified that we need a private colormap */ | 632 check to see if the user specified that we need a private colormap */ |
496 if (visual == DefaultVisual (dpy, screen)) | 633 if (visual == DefaultVisual (dpy, screen)) |
507 cmap = DefaultColormap (dpy, screen); | 644 cmap = DefaultColormap (dpy, screen); |
508 } | 645 } |
509 } | 646 } |
510 else | 647 else |
511 { | 648 { |
512 /* We have to create a matching colormap anyway... | 649 if ( best_visual_found ) |
513 ### think about using standard colormaps (need the Xmu libs?) */ | 650 { |
514 cmap = XCreateColormap (dpy, RootWindow(dpy, screen), visual, AllocNone); | 651 cmap = XCreateColormap (dpy, RootWindow (dpy, screen), visual, AllocNone); |
515 XInstallColormap (dpy, cmap); | 652 } |
653 else | |
654 { | |
655 /* We have to create a matching colormap anyway... | |
656 ### think about using standard colormaps (need the Xmu libs?) */ | |
657 cmap = XCreateColormap(dpy, RootWindow(dpy, screen), visual, AllocNone); | |
658 XInstallColormap(dpy, cmap); | |
659 } | |
516 } | 660 } |
517 } | 661 } |
518 | 662 |
519 DEVICE_X_VISUAL (d) = visual; | 663 DEVICE_X_VISUAL (d) = visual; |
520 DEVICE_X_COLORMAP (d) = cmap; | 664 DEVICE_X_COLORMAP (d) = cmap; |